summaryrefslogtreecommitdiff
path: root/src/gsmd
diff options
context:
space:
mode:
authorlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-17 08:31:21 +0000
committerlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-17 08:31:21 +0000
commitbe174b78167bf9f2b77901b4b318606144a5ae58 (patch)
treeb3f517006fd9772f088c989eff7f5513bf100743 /src/gsmd
parent90bf3b4473da30d8b89c8ecfabcce42c0e4fe484 (diff)
From: Andrzej Zaborowski <balrog@zabor.org>
Date: Fri, 27 Jul 2007 19:39:15 +0200 Subject: [PATCH] Cell Broadcast message decoding and presentation in libgsmd-tool. This time Cell Broadcast is tested to work, I should have made tests earlier. Now I'm correctly getting a CB message with the human readable name of the city and district when I'm connecting. In the previous patches the CB PDU was not being decoded at all. git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2723 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/gsmd')
-rw-r--r--src/gsmd/sms_cb.c42
-rw-r--r--src/gsmd/sms_pdu.c29
2 files changed, 43 insertions, 28 deletions
diff --git a/src/gsmd/sms_cb.c b/src/gsmd/sms_cb.c
index 1ae337e..0ffe563 100644
--- a/src/gsmd/sms_cb.c
+++ b/src/gsmd/sms_cb.c
@@ -67,7 +67,7 @@ static int sms_list_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
struct gsmd_ucmd *ucmd;
struct gsmd_sms_list msg;
int i, idx, stat, len, cr;
- u_int8_t pdu[MAX_PDU_SIZE];
+ u_int8_t pdu[SMS_MAX_PDU_SIZE];
if (cmd->ret && cmd->ret != -255)
return 0;
@@ -86,7 +86,7 @@ static int sms_list_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
msg.stat = stat;
msg.is_last = (cmd->ret == 0);
for (i = 0; resp[cr] >= '0' && resp[cr + 1] >= '0' &&
- i < MAX_PDU_SIZE; i ++) {
+ i < SMS_MAX_PDU_SIZE; i ++) {
if (sscanf(resp + cr, "%2hhX", &pdu[i]) < 1) {
gsmd_log(GSMD_DEBUG, "malformed input (%i)\n", i);
return -EINVAL;
@@ -115,7 +115,7 @@ static int sms_read_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
struct gsmd_ucmd *ucmd;
struct gsmd_sms_list msg;
int i, stat, len, cr;
- u_int8_t pdu[MAX_PDU_SIZE];
+ u_int8_t pdu[SMS_MAX_PDU_SIZE];
if (cmd->ret)
return 0;
@@ -134,7 +134,7 @@ static int sms_read_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
msg.stat = stat;
msg.is_last = 1;
for (i = 0; resp[cr] >= '0' && resp[cr + 1] >= '0' &&
- i < MAX_PDU_SIZE; i ++) {
+ i < SMS_MAX_PDU_SIZE; i ++) {
if (sscanf(resp + cr, "%2hhX", &pdu[i]) < 1) {
gsmd_log(GSMD_DEBUG, "malformed input (%i)\n", i);
return -EINVAL;
@@ -475,7 +475,7 @@ static int cmti_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
static int cmt_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
{
/* TODO: TEXT mode */
- u_int8_t pdu[MAX_PDU_SIZE];
+ u_int8_t pdu[SMS_MAX_PDU_SIZE];
const char *comma = strchr(param, ',');
char *cr;
int i;
@@ -502,7 +502,8 @@ static int cmt_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
}
cr ++;
- for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < MAX_PDU_SIZE; i ++) {
+ for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < SMS_MAX_PDU_SIZE;
+ i ++) {
if (sscanf(cr, "%2hhX", &pdu[i]) < 1) {
gsmd_log(GSMD_DEBUG, "malformed input (%i)\n", i);
talloc_free(ucmd);
@@ -531,11 +532,6 @@ static int cbmi_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
if (!ucmd)
return -ENOMEM;
- ucmd->hdr.version = GSMD_PROTO_VERSION;
- ucmd->hdr.msg_type = GSMD_MSG_EVENT;
- ucmd->hdr.msg_subtype = GSMD_EVT_IN_CBM;
- ucmd->hdr.len = sizeof(*aux);
-
aux = (struct gsmd_evt_auxdata *) ucmd->buf;
if (sscanf(param, "\"%2[A-Z]\",%i", memstr, &aux->u.cbm.index) < 2) {
talloc_free(ucmd);
@@ -551,20 +547,20 @@ static int cbmi_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
static int cbm_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
{
/* TODO: TEXT mode */
- u_int8_t pdu[MAX_PDU_SIZE];
+ u_int8_t pdu[CBM_MAX_PDU_SIZE];
char *cr;
int i;
struct gsmd_evt_auxdata *aux;
- struct gsmd_sms_list *msg;
+ struct gsmd_cbm *msg;
struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT,
GSMD_EVT_IN_CBM, sizeof(struct gsmd_evt_auxdata) +
- sizeof(struct gsmd_sms_list));
+ sizeof(struct gsmd_cbm));
if (!ucmd)
return -ENOMEM;
aux = (struct gsmd_evt_auxdata *) ucmd->buf;
- msg = (struct gsmd_sms_list *) aux->data;
+ msg = (struct gsmd_cbm *) aux->data;
len = strtoul(param, &cr, 10);
if (cr[0] != '\n') {
@@ -573,7 +569,8 @@ static int cbm_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
}
cr ++;
- for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < MAX_PDU_SIZE; i ++) {
+ for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < CBM_MAX_PDU_SIZE;
+ i ++) {
if (sscanf(cr, "%2hhX", &pdu[i]) < 1) {
gsmd_log(GSMD_DEBUG, "malformed input (%i)\n", i);
talloc_free(ucmd);
@@ -583,7 +580,7 @@ static int cbm_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
}
aux->u.cbm.inlined = 1;
- if (sms_pdu_to_msg(msg, pdu, len, i)) {
+ if (cbs_pdu_to_msg(msg, pdu, len, i)) {
gsmd_log(GSMD_DEBUG, "malformed PDU\n");
talloc_free(ucmd);
return -EINVAL;
@@ -617,7 +614,7 @@ static int cdsi_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
static int cds_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
{
/* TODO: TEXT mode */
- u_int8_t pdu[MAX_PDU_SIZE];
+ u_int8_t pdu[SMS_MAX_PDU_SIZE];
char *cr;
int i;
struct gsmd_evt_auxdata *aux;
@@ -639,7 +636,8 @@ static int cds_parse(char *buf, int len, const char *param, struct gsmd *gsmd)
}
cr ++;
- for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < MAX_PDU_SIZE; i ++) {
+ for (i = 0; cr[0] >= '0' && cr[1] >= '0' && i < SMS_MAX_PDU_SIZE;
+ i ++) {
if (sscanf(cr, "%2hhX", &pdu[i]) < 1) {
gsmd_log(GSMD_DEBUG, "malformed input (%i)\n", i);
talloc_free(ucmd);
@@ -714,11 +712,5 @@ int sms_cb_network_init(struct gsmd *gsmd)
*/
ret |= gsmd_simplecmd(gsmd, "AT+CNMI=2,1,2,1,0");
- /* Store into ME/TA and notify */
- ret |= gsmd_simplecmd(gsmd, "AT+CSBS=1");
-
- /* Store into ME/TA and notify */
- ret |= gsmd_simplecmd(gsmd, "AT+CSDS=2");
-
return ret;
}
diff --git a/src/gsmd/sms_pdu.c b/src/gsmd/sms_pdu.c
index c9b9327..665fdcb 100644
--- a/src/gsmd/sms_pdu.c
+++ b/src/gsmd/sms_pdu.c
@@ -26,6 +26,7 @@
#include <gsmd/gsmd.h>
#include <gsmd/usock.h>
+#include <gsmd/sms.h>
static int sms_number_bytelen(u_int8_t type, u_int8_t len)
{
@@ -50,7 +51,7 @@ static int sms_data_bytelen(u_int8_t data_coding_scheme, u_int8_t len)
return 0;
}
-static int sms_address2ascii(struct gsmd_addr *dst, u_int8_t *src)
+static int sms_address2ascii(struct gsmd_addr *dst, const u_int8_t *src)
{
int i;
@@ -80,7 +81,7 @@ static int sms_address2ascii(struct gsmd_addr *dst, u_int8_t *src)
}
int sms_pdu_to_msg(struct gsmd_sms_list *dst,
- u_int8_t *src, int pdulen, int len)
+ const u_int8_t *src, int pdulen, int len)
{
int i, vpf;
if (len < 1 || len < 1 + src[0] + pdulen || pdulen < 1)
@@ -200,7 +201,7 @@ int sms_pdu_to_msg(struct gsmd_sms_list *dst,
}
/* Refer to GSM 03.40 subclause 9.2.3.3, for SMS-SUBMIT */
-int sms_pdu_make_smssubmit(char *dest, struct gsmd_sms_submit *src)
+int sms_pdu_make_smssubmit(char *dest, const struct gsmd_sms_submit *src)
{
/* FIXME: ALPHANUMERIC encoded addresses can be longer than 13B */
u_int8_t header[15 + GSMD_ADDR_MAXLEN];
@@ -259,3 +260,25 @@ int sms_pdu_make_smssubmit(char *dest, struct gsmd_sms_submit *src)
return pos + len;
}
+
+/* Refer to GSM 03.41 subclause 9.3 */
+int cbs_pdu_to_msg(struct gsmd_cbm *dst, u_int8_t *src, int pdulen, int len)
+{
+ if (len != pdulen || len != CBM_MAX_PDU_SIZE)
+ return 1;
+
+ dst->serial.scope = (src[0] >> 6) & 3;
+ dst->serial.msg_code = ((src[0] << 4) | (src[1] >> 4)) & 0x3ff;
+ dst->serial.update_num = src[1] & 0xf;
+
+ dst->msg_id = (src[2] << 8) | src[3];
+
+ dst->language = src[4] & 0xf;
+ dst->coding_scheme = ((src[4] >> 4) & 3) << 2;
+
+ dst->pages = src[5] & 0xf;
+ dst->page = src[5] >> 4;
+
+ memcpy(dst->data, src + 6, len - 6);
+ return 0;
+}
personal git repositories of Harald Welte. Your mileage may vary