📄 sms_cb.c
字号:
ts0705_memtype_name[storage[1]], ts0705_memtype_name[storage[2]]); cmd = atcmd_fill(buf, atcmd_len + 1, NULL, gu, gph->id, NULL); break; case GSMD_SMS_GET_SERVICE_CENTRE: cmd = atcmd_fill("AT+CSCA?", 8 + 1, &usock_get_smsc_cb, gu, 0, NULL); break; case GSMD_SMS_SET_SERVICE_CENTRE: if (len < sizeof(*gph) + sizeof(struct gsmd_addr)) return -EINVAL; ga = (struct gsmd_addr *) ((void *) gph + sizeof(*gph)); atcmd_len = sprintf(buf, "AT+CSCA=\"%s\",%i", ga->number, ga->type); cmd = atcmd_fill(buf, atcmd_len + 1, NULL, gu, gph->id, NULL); break; default: return -ENOSYS; } if (!cmd) return -ENOMEM; gsmd_log(GSMD_DEBUG, "%s\n", cmd ? cmd->buf : 0); return atcmd_submit(gu->gsmd, cmd);}/* main unix socket Cell Broadcast receiver */int usock_rcv_cb(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, int len){ struct gsmd_atcmd *cmd; switch (gph->msg_subtype) { case GSMD_CB_SUBSCRIBE: cmd = atcmd_fill("AT+CSCB=1", 9 + 1, NULL, gu->gsmd, 0, NULL); break; case GSMD_CB_UNSUBSCRIBE: cmd = atcmd_fill("AT+CSCB=0", 9 + 1, NULL, gu->gsmd, 0, NULL); break; default: return -ENOSYS; } if (!cmd) return -ENOMEM; return atcmd_submit(gu->gsmd, cmd);}/* Unsolicited messages related to SMS / CB */static int cmti_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ char memstr[3]; struct gsmd_evt_auxdata *aux; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_SMS, sizeof(struct gsmd_evt_auxdata)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; if (sscanf(param, "\"%2[A-Z]\",%i", memstr, &aux->u.sms.index) < 2) { talloc_free(ucmd); return -EINVAL; } aux->u.sms.inlined = 0; aux->u.sms.memtype = parse_memtype(memstr); return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_SMS);}static int cmt_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ /* TODO: TEXT mode */ u_int8_t pdu[SMS_MAX_PDU_SIZE]; const char *cr = NULL; int i; char tmp[64]; struct gsm_extrsp *er; struct gsmd_evt_auxdata *aux; struct gsmd_sms_list *msg; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_SMS, sizeof(struct gsmd_evt_auxdata) + sizeof(struct gsmd_sms_list)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; msg = (struct gsmd_sms_list *) aux->data; cr = strchr(param, '\n'); if (!cr) { talloc_free(ucmd); return -EAGAIN; } strncpy(tmp, param, (cr-param)); tmp[(cr-param)] = '\0'; er = extrsp_parse(gsmd_tallocs, tmp); if ( !er ) { talloc_free(ucmd); return -ENOMEM; } //extrsp_dump(er); if ( er->num_tokens == 2 && er->tokens[0].type == GSMD_ECMD_RTT_EMPTY && er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { aux->u.sms.alpha[0] = '\0'; len = er->tokens[1].u.numeric; } else if ( er->num_tokens == 2 && er->tokens[0].type == GSMD_ECMD_RTT_STRING && er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { strcpy(aux->u.sms.alpha, er->tokens[0].u.string); len = er->tokens[1].u.numeric; } else { talloc_free(ucmd); talloc_free(er); return -EINVAL; } cr ++; 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); return -EINVAL; } cr += 2; } aux->u.sms.inlined = 1; if (sms_pdu_to_msg(msg, pdu, len, i)) { gsmd_log(GSMD_DEBUG, "malformed PDU\n"); talloc_free(ucmd); return -EINVAL; } return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_SMS);}static int cbmi_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ char memstr[3]; struct gsmd_evt_auxdata *aux; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_CBM, sizeof(struct gsmd_evt_auxdata)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; if (sscanf(param, "\"%2[A-Z]\",%i", memstr, &aux->u.cbm.index) < 2) { talloc_free(ucmd); return -EINVAL; } aux->u.cbm.inlined = 0; aux->u.cbm.memtype = parse_memtype(memstr); return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_CBM);}static int cbm_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ /* TODO: TEXT mode */ u_int8_t pdu[CBM_MAX_PDU_SIZE]; char *cr; int i; struct gsmd_evt_auxdata *aux; 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_cbm)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; msg = (struct gsmd_cbm *) aux->data; len = strtoul(param, &cr, 10); if (cr[0] != '\n') { talloc_free(ucmd); return -EAGAIN; } cr ++; 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); return -EINVAL; } cr += 2; } aux->u.cbm.inlined = 1; if (cbs_pdu_to_msg(msg, pdu, len, i)) { gsmd_log(GSMD_DEBUG, "malformed PDU\n"); talloc_free(ucmd); return -EINVAL; } return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_CBM);}static int cdsi_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ char memstr[3]; struct gsmd_evt_auxdata *aux; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_DS, sizeof(struct gsmd_evt_auxdata)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; if (sscanf(param, "\"%2[A-Z]\",%i", memstr, &aux->u.ds.index) < 2) { talloc_free(ucmd); return -EINVAL; } aux->u.ds.inlined = 0; aux->u.ds.memtype = parse_memtype(memstr); return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_DS);}static int cds_parse(const char *buf, int len, const char *param, struct gsmd *gsmd){ /* TODO: TEXT mode */ u_int8_t pdu[SMS_MAX_PDU_SIZE]; char *cr; int i; struct gsmd_evt_auxdata *aux; struct gsmd_sms_list *msg; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_DS, sizeof(struct gsmd_evt_auxdata) + sizeof(struct gsmd_sms_list)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; msg = (struct gsmd_sms_list *) aux->data; len = strtoul(param, &cr, 10); if (cr[0] != '\n') { talloc_free(ucmd); return -EAGAIN; } cr ++; 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); return -EINVAL; } cr += 2; } aux->u.ds.inlined = 1; if (sms_pdu_to_msg(msg, pdu, len, i)) { gsmd_log(GSMD_DEBUG, "malformed PDU\n"); talloc_free(ucmd); return -EINVAL; } return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_DS);}static const struct gsmd_unsolicit gsm0705_unsolicit[] = { { "+CMTI", &cmti_parse }, /* SMS Deliver Index (stored in ME/TA)*/ { "+CMT", &cmt_parse }, /* SMS Deliver to TE */ { "+CBMI", &cbmi_parse }, /* Cell Broadcast Message Index */ { "+CBM", &cbm_parse }, /* Cell Broadcast Message */ { "+CDSI", &cdsi_parse }, /* SMS Status Report */ { "+CDS", &cds_parse }, /* SMS Status Index (stored in ME/TA) */};int sms_cb_init(struct gsmd *gsmd){ struct gsmd_atcmd *atcmd; char buffer[10]; unsolicited_register_array(gsm0705_unsolicit, ARRAY_SIZE(gsm0705_unsolicit)); /* If text mode, set the encoding */ if (gsmd->flags & GSMD_FLAG_SMS_FMT_TEXT) { atcmd = atcmd_fill("AT+CSCS=\"IRA\"", 13 + 1, NULL, gsmd, 0, NULL); if (!atcmd) return -ENOMEM; atcmd_submit(gsmd, atcmd); } /* Switch into desired mode (Section 3.2.3) */ atcmd = atcmd_fill(buffer, snprintf(buffer, sizeof(buffer), "AT+CMGF=%i", (gsmd->flags & GSMD_FLAG_SMS_FMT_TEXT) ? GSMD_SMS_FMT_TEXT : GSMD_SMS_FMT_PDU) + 1, NULL, gsmd, 0, NULL); if (!atcmd) return -ENOMEM; return atcmd_submit(gsmd, atcmd);}/* Called everytime the phone registers to the network and we want to start * receiving messages. */int sms_cb_network_init(struct gsmd *gsmd){ int ret = 0; ret |= gsmd_simplecmd(gsmd, "AT+CSMS=0"); /* * Set the New Message Indications properties to values that are * likely supported. We will get a: * +CMTI on a new incoming SMS, * +CBM on a new incoming CB, * +CDS on an SMS status report. * * FIXME: ask for supported +CNMI values first. */ ret |= gsmd_simplecmd(gsmd, "AT+CNMI=2,1,2,1,0"); return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -