Index: common/links/atbus.c =================================================================== RCS file: /sources/gnokii/gnokii/common/links/atbus.c,v retrieving revision 1.50 diff -u -p -r1.50 atbus.c --- common/links/atbus.c 6 Jul 2007 19:31:06 -0000 1.50 +++ common/links/atbus.c 7 Jul 2007 18:57:19 -0000 @@ -226,6 +226,9 @@ static void atbus_rx_statemachine(unsign } else if (!strncmp(start + 1, "CLCC:", 5)) { sm_incoming_function(GN_OP_AT_Ring, start, bi->rbuf_pos - 1 - (start - bi->rbuf), sm); unsolicited = 1; + } else if (!strncmp(start + 1, "CMTI:", 5)) { + sm_incoming_function(GN_OP_AT_IncomingSMS, start, bi->rbuf_pos - 1 - (start - bi->rbuf), sm); + unsolicited = 1; } } if (unsolicited) { Index: common/phones/atgen.c =================================================================== RCS file: /sources/gnokii/gnokii/common/phones/atgen.c,v retrieving revision 1.150 diff -u -p -r1.150 atgen.c --- common/phones/atgen.c 7 Jul 2007 12:01:19 -0000 1.150 +++ common/phones/atgen.c 7 Jul 2007 17:21:49 -0000 @@ -77,6 +77,7 @@ static gn_error ReplyGetNetworkInfo(int static gn_error ReplyRing(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state); static gn_error ReplyGetDateTime(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state); static gn_error ReplyGetActiveCalls(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state); +static gn_error ReplyIncomingSMS(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state); static gn_error AT_Identify(gn_data *data, struct gn_statemachine *state); static gn_error AT_GetModel(gn_data *data, struct gn_statemachine *state); @@ -114,6 +115,7 @@ static gn_error AT_SetDateTime(gn_data * static gn_error AT_GetDateTime(gn_data *data, struct gn_statemachine *state); static gn_error AT_SendDTMF(gn_data *data, struct gn_statemachine *state); static gn_error AT_GetActiveCalls(gn_data *data, struct gn_statemachine *state); +static gn_error AT_OnSMS(gn_data *data, struct gn_statemachine *state); typedef struct { int gop; @@ -163,6 +165,8 @@ static at_function_init_type at_function { GN_OP_GetDateTime, AT_GetDateTime, ReplyGetDateTime }, { GN_OP_SendDTMF, AT_SendDTMF, Reply }, { GN_OP_GetActiveCalls, AT_GetActiveCalls, ReplyGetActiveCalls }, + { GN_OP_OnSMS, AT_OnSMS, Reply }, + { GN_OP_AT_IncomingSMS, NULL, ReplyIncomingSMS }, }; char *strip_quotes(char *s) @@ -1243,6 +1247,21 @@ static gn_error AT_GetActiveCalls(gn_dat return sm_block_no_retry(GN_OP_GetActiveCalls, data, state); } +static gn_error AT_OnSMS(gn_data *data, struct gn_statemachine *state) +{ + gn_error error; + + if (sm_message_send(12, GN_OP_OnSMS, "AT+CNMI=2,1\r", state)) + return GN_ERR_NOTREADY; + + error = sm_block_no_retry(GN_OP_OnSMS, data, state); + if (error == GN_ERR_NONE) { + AT_DRVINST(state)->on_sms = data->on_sms; + AT_DRVINST(state)->sms_callback_data = data->callback_data; + } + return error; +} + static gn_error ReplyReadPhonebook(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state) { at_driver_instance *drvinst = AT_DRVINST(state); @@ -2002,6 +2021,72 @@ static gn_error ReplyRing(int messagetyp return GN_ERR_UNSOLICITED; } +static gn_error ReplyIncomingSMS(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state) +{ + at_driver_instance *drvinst = AT_DRVINST(state); + at_line_buffer buf; + char *memory, *pos; + int index, i; + gn_memory_type mem; + int freesms = 0; + gn_error error; + + if (!drvinst->on_sms) return GN_ERR_UNSOLICITED; + + buf.line1 = buffer; + buf.length= length; + splitlines(&buf); + + mem = GN_MT_XX; + + if (strncmp(buf.line1, "+CMTI: ", 7)) + return GN_ERR_UNSOLICITED; + + pos = strrchr(buf.line1, ','); + if (pos == NULL) + return GN_ERR_UNSOLICITED; + pos[0] = '\0'; + pos++; + index = atoi(pos); + + memory = strip_quotes(buf.line1 + 7); + if (memory == NULL) + return GN_ERR_UNSOLICITED; + for (i = 0; i < NR_MEMORIES; i++) { + if (!strcmp(memory, memorynames[i])) { + mem = i; + break; + } + } + + if (mem == GN_MT_XX) + return GN_ERR_UNSOLICITED; + + fprintf (stdout, "Received message folder %s index %d\n", memorynames[mem], index); + + if (!data->sms) { + freesms = 1; + data->sms = calloc(1, sizeof(gn_sms)); + if (!data->sms) + return GN_ERR_INTERNALERROR; + } + + memset (data->sms, 0, sizeof (gn_sms)); + data->sms->memory_type = mem; + data->sms->number = index; + + error = gn_sms_get (data, state); + if (error == GN_ERR_NONE) { + error = GN_ERR_UNSOLICITED; + drvinst->on_sms(data->sms, state, drvinst->sms_callback_data); + } + + if (freesms) + free(data->sms); + + return error; +} + static gn_error ReplyGetNetworkInfo(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state) { at_driver_instance *drvinst = AT_DRVINST(state); Index: include/phones/atgen.h =================================================================== RCS file: /sources/gnokii/gnokii/include/phones/atgen.h,v retrieving revision 1.27 diff -u -p -r1.27 atgen.h --- include/phones/atgen.h 7 Jul 2007 12:21:21 -0000 1.27 +++ include/phones/atgen.h 7 Jul 2007 17:21:50 -0000 @@ -45,6 +45,7 @@ typedef enum { GN_OP_AT_Prompt, GN_OP_AT_GetMemoryRange, GN_OP_AT_Ring, + GN_OP_AT_IncomingSMS, GN_OP_AT_Max /* don't append anything after this entry */ } at_operation;