? motorolaSMSD_chodroff20080918.patch Index: common/gsm-sms.c =================================================================== RCS file: /sources/gnokii/gnokii/common/gsm-sms.c,v retrieving revision 1.184 diff -u -r1.184 gsm-sms.c --- common/gsm-sms.c 10 Sep 2008 21:00:18 -0000 1.184 +++ common/gsm-sms.c 18 Sep 2008 06:12:51 -0000 @@ -996,6 +996,12 @@ return gn_sm_functions(GN_OP_GetSMS, data, state); } +gn_error gn_sms_request_next(gn_data *data, struct gn_statemachine *state) +{ + if (!data->raw_sms) return GN_ERR_INTERNALERROR; + return gn_sm_functions(GN_OP_GetNextSMS, data, state); +} + /** * gn_sms_get- High-level function for reading SMS * @data: GSM data for the phone driver @@ -1025,6 +1031,24 @@ return gn_sms_parse(data); } +GNOKII_API gn_error gn_sms_get_next(gn_data *data, struct gn_statemachine *state) +{ + gn_error error; + gn_sms_raw rawsms; + + if (!data->sms) + return GN_ERR_INTERNALERROR; + if (data->sms->memory_type > GN_MT_LAST) + return GN_ERR_INVALIDMEMORYTYPE; + memset(&rawsms, 0, sizeof(gn_sms_raw)); + rawsms.memory_type = data->sms->memory_type; + data->raw_sms = &rawsms; + error = gn_sms_request_next(data, state); + ERROR(); + data->sms->status = rawsms.status; + return gn_sms_parse(data); +} + /** * gn_sms_delete - High-level function for deleting SMS * @data: GSM data for the phone driver Index: common/phones/atgen.c =================================================================== RCS file: /sources/gnokii/gnokii/common/phones/atgen.c,v retrieving revision 1.207 diff -u -r1.207 atgen.c --- common/phones/atgen.c 15 Sep 2008 08:49:49 -0000 1.207 +++ common/phones/atgen.c 18 Sep 2008 06:12:54 -0000 @@ -574,7 +574,7 @@ case 318: return GN_ERR_CODEREQUIRED; /* SIM PUK2 required */ case 320: return GN_ERR_FAILED; /* memory failure */ - case 321: return GN_ERR_INVALIDLOCATION;/* invalid memory index */ + case 321: return GN_ERR_EMPTYLOCATION; /* empty memory index */ case 322: return GN_ERR_MEMORYFULL; /* memory full */ case 330: return GN_ERR_FAILED; /* SMSC address unknown */ Index: common/phones/atmot.c =================================================================== RCS file: /sources/gnokii/gnokii/common/phones/atmot.c,v retrieving revision 1.2 diff -u -r1.2 atmot.c --- common/phones/atmot.c 4 Dec 2007 19:27:34 -0000 1.2 +++ common/phones/atmot.c 18 Sep 2008 06:12:54 -0000 @@ -81,10 +81,132 @@ return GN_ERR_NONE; } +static gn_error AT_GetNextSMS(gn_data *data, struct gn_statemachine *state) +{ + unsigned char req[32]; + gn_error err; + + at_set_charset(data, state, AT_CHAR_GSM); + err = AT_SetSMSMemoryType(data->raw_sms->memory_type, state); + + if (err) + return err; + + err = state->driver.functions(GN_OP_AT_SetPDUMode, data, state); + if (err) { + dprintf("PDU mode is not supported by gnokii. This mobile supports only TEXT mode\n"); + return err; + } + dprintf("PDU mode set\n"); + + snprintf(req, sizeof(req), "AT+CMGL=%d\r", 4); + if (sm_message_send(strlen(req), GN_OP_GetNextSMS, req, state)) + return GN_ERR_NOTREADY; + return sm_block_no_retry(GN_OP_GetNextSMS, data, state); +} + +static gn_error ReplyGetNextSMS(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state) +{ + at_line_buffer buf; + gn_error ret = GN_ERR_NONE; + unsigned int sms_len, pdu_flags; + unsigned char *tmp; + gn_error error; + at_driver_instance *drvinst = AT_DRVINST(state); + + if ((error = at_error_get(buffer, state)) != GN_ERR_NONE) + return error; + + buf.line1 = buffer + 1; + buf.length = length; + + splitlines(&buf); + + if (!data->raw_sms) + return GN_ERR_INTERNALERROR; + + /* Try to figure out the status first */ + tmp = strchr(buf.line2, ','); + if (tmp != NULL && ((char *) tmp - buf.line2 - strlen("+CMGR: ")) >= 1) { + char *status; + int len; + + len = (char *) tmp - buf.line2 - strlen("+CMGR: "); + status = malloc(len + 1); + if (!status) { + dprintf("Not enough memory for buffer.\n"); + return GN_ERR_INTERNALERROR; + } + + memcpy(status, buf.line2 + strlen("+CMGR: "), len); + status[len] = '\0'; + if (strstr(status, "UNREAD")) { + data->raw_sms->status = GN_SMS_Unread; + } else if (strstr(status, "READ")) { + data->raw_sms->status = GN_SMS_Read; + } else if (strstr(status, "UNSENT")) { + data->raw_sms->status = GN_SMS_Unsent; + } else if (strstr(status, "SENT")) { + data->raw_sms->status = GN_SMS_Sent; + } else { + int s; + + s = atoi(status); + switch (s) { + case 0: + data->raw_sms->status = GN_SMS_Unread; + break; + case 1: + data->raw_sms->status = GN_SMS_Read; + break; + case 2: + data->raw_sms->status = GN_SMS_Unsent; + break; + case 3: + data->raw_sms->status = GN_SMS_Sent; + break; + } + } + data->raw_sms->number=atoi(status); + data->sms->number=atoi(status); + + free(status); + } + + tmp = strrchr(buf.line2, ','); + if (!tmp) + return GN_ERR_EMPTYLOCATION; + sms_len = atoi(tmp+1); + if (sms_len == 0) + return GN_ERR_EMPTYLOCATION; + + sms_len = strlen(buf.line3) / 2; + tmp = calloc(sms_len, 1); + if (!tmp) { + dprintf("Not enough memory for buffer.\n"); + return GN_ERR_INTERNALERROR; + } + dprintf("%s\n", buf.line3); + hex2bin(tmp, buf.line3, sms_len); + + if (drvinst->no_smsc) { + pdu_flags = GN_SMS_PDU_NOSMSC; + } else { + pdu_flags = GN_SMS_PDU_DEFAULT; + } + ret = gn_sms_pdu2raw(data->raw_sms, tmp, sms_len, pdu_flags); + + free(tmp); + return ret; +} + void at_motorola_init(char* foundmodel, char* setupmodel, struct gn_statemachine *state) { /* Motorolas support mode 3 and 0, but mode 0 is pretty useless */ AT_DRVINST(state)->cnmi_mode = 3; identify = at_insert_recv_function(GN_OP_Identify, ReplyIdentify, state); + at_insert_send_function(GN_OP_GetNextSMS, AT_GetNextSMS, state); + at_insert_recv_function(GN_OP_GetNextSMS, ReplyGetNextSMS, state); + } Index: include/gnokii-internal.h =================================================================== RCS file: /sources/gnokii/gnokii/include/gnokii-internal.h,v retrieving revision 1.40 diff -u -r1.40 gnokii-internal.h --- include/gnokii-internal.h 16 Jun 2008 14:48:24 -0000 1.40 +++ include/gnokii-internal.h 18 Sep 2008 06:12:54 -0000 @@ -48,6 +48,7 @@ gn_error gn_sms_parse(gn_data *data); gn_error gn_sms_pdu2raw(gn_sms_raw *rawsms, unsigned char *pdu, int pdu_len, int flags); gn_error gn_sms_request(gn_data *data, struct gn_statemachine *state); +gn_error gn_sms_request_next(gn_data *data, struct gn_statemachine *state); gn_error sms_prepare(gn_sms *sms, gn_sms_raw *rawsms); gn_timestamp *sms_timestamp_unpack(unsigned char *number, gn_timestamp *dt); unsigned char *sms_timestamp_pack(gn_timestamp *dt, unsigned char *number); Index: smsd/lowlevel.c =================================================================== RCS file: /sources/gnokii/gnokii/smsd/lowlevel.c,v retrieving revision 1.53 diff -u -r1.53 lowlevel.c --- smsd/lowlevel.c 27 Jul 2008 16:47:44 -0000 1.53 +++ smsd/lowlevel.c 18 Sep 2008 06:12:55 -0000 @@ -229,15 +229,24 @@ msg = g_malloc (sizeof (gn_sms)); memset (msg, 0, sizeof (gn_sms)); msg->memory_type = smsdConfig.memoryType; - msg->number = 0; + //msg->number = 0; data.sms = msg; - +/* if ((error = gn_sms_get (&data, sm)) == GN_ERR_INVALIDLOCATION) smsdConfig.firstSMS = 1; else smsdConfig.firstSMS = 0; - +*/ gn_log_xdebug ("First SMS position is %d\n", smsdConfig.firstSMS); + + if ((error = gn_sms_get_next (&data, sm)) == GN_ERR_INVALIDLOCATION){ + dprintf("Unable to find next sms message\n"); + smsdConfig.firstSMS = 0; + } + else{ + smsdConfig.firstSMS = data.raw_sms->number; + } + g_free (msg); } @@ -248,10 +257,10 @@ msg = g_malloc (sizeof (gn_sms)); memset (msg, 0, sizeof (gn_sms)); msg->memory_type = smsdConfig.memoryType; - msg->number = i++; + //msg->number = i++; data.sms = msg; - gn_log_xdebug("Reading SMS %d\n", i-1); - if ((error = gn_sms_get (&data, sm)) == GN_ERR_NONE) +// gn_log_xdebug("Reading SMS %d\n", i-1); + if ((error = gn_sms_get_next (&data, sm)) == GN_ERR_NONE) { phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg); phoneMonitor.sms.number++;