summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fw/fe310/eos/net/cell.c74
-rw-r--r--fw/fe310/eos/net/cell.h13
2 files changed, 82 insertions, 5 deletions
diff --git a/fw/fe310/eos/net/cell.c b/fw/fe310/eos/net/cell.c
index c1feb0a..b0eb475 100644
--- a/fw/fe310/eos/net/cell.c
+++ b/fw/fe310/eos/net/cell.c
@@ -8,6 +8,8 @@
#include "cell.h"
+#define GSM_TS_SIZE 25
+
static eos_evt_handler_t evt_handler[EOS_CELL_MAX_MTYPE];
static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
@@ -193,3 +195,75 @@ unsigned char *eos_cell_voice_pcm_buffer(uint16_t *offset) {
*offset = 1;
return buffer + *offset;
}
+
+int eos_cell_sms_send(char *num, char *text, unsigned char *buffer, int sync) {
+ int async;
+ size_t num_len, text_len;
+ uint16_t len;
+
+ num_len = strlen(num);
+ text_len = strlen(text);
+ if (num_len > EOS_CELL_MAX_DIAL_STR) return EOS_ERR_SIZE;
+ if (text_len > EOS_CELL_MAX_SMS_TEXT) return EOS_ERR_SIZE;
+
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ } else {
+ async = !sync;
+ }
+ buffer[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG;
+ buffer[1] = (*num == '+' ? EOS_CELL_SMS_ADDRTYPE_INTL : EOS_CELL_SMS_ADDRTYPE_OTHER);
+ buffer[2] = num_len;
+ len = 3;
+ strcpy(buffer + len, num);
+ len += num_len;
+ strcpy(buffer + len, text);
+ len += text_len;
+ return _eos_net_send(EOS_NET_MTYPE_CELL, buffer, len, async, 1);
+}
+
+int eos_cell_sms_recv(unsigned char *buffer, uint16_t len, char *num, uint16_t num_size, char *text, uint16_t text_size) {
+ char *_num, *_text;
+ uint16_t _num_len, _text_len;
+ int rv;
+
+ rv = eos_cell_sms_parse(buffer, len, &_num, &_num_len, &_text, &_text_len);
+ if (rv) return rv;
+ if (num_size < _num_len + 1) return EOS_ERR_SIZE;
+ if (text_size < _text_len + 1) return EOS_ERR_SIZE;
+ memcpy(num, _num, _num_len);
+ num[_num_len] = '\0';
+ memcpy(text, _text, _text_len);
+ text[_text_len] = '\0';
+
+ return EOS_OK;
+}
+
+int eos_cell_sms_parse(unsigned char *buffer, uint16_t len, char **num, uint16_t *num_len, char **text, uint16_t *text_len) {
+ uint16_t _num_len;
+
+ if (len < 4 + GSM_TS_SIZE) return EOS_ERR_SIZE;
+
+ if (buffer[0] != (EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG)) return EOS_ERR_NET;
+ buffer += 3 + GSM_TS_SIZE;
+ len -= 3 + GSM_TS_SIZE;
+
+ _num_len = *buffer;
+ if (_num_len > EOS_CELL_MAX_DIAL_STR) return EOS_ERR_SIZE;
+ if ((_num_len == 0) || (len < (_num_len + 1))) return EOS_ERR_SIZE;
+ if (num && num_len) {
+ *num = buffer + 1;
+ *num_len = _num_len;
+ }
+ buffer += _num_len + 1;
+ len -= _num_len + 1;
+
+ if (len > EOS_CELL_MAX_SMS_TEXT) return EOS_ERR_SIZE;
+ if (text && text_len) {
+ *text = buffer;
+ *text_len = len;
+ }
+
+ return EOS_OK;
+}
diff --git a/fw/fe310/eos/net/cell.h b/fw/fe310/eos/net/cell.h
index 1e6d1b2..2717eb5 100644
--- a/fw/fe310/eos/net/cell.h
+++ b/fw/fe310/eos/net/cell.h
@@ -29,10 +29,9 @@
#define EOS_CELL_MTYPE_VOICE_BUSY 9
#define EOS_CELL_MTYPE_VOICE_ERR 10
-#define EOS_CELL_MTYPE_SMS_LIST 1
-#define EOS_CELL_MTYPE_SMS_SEND 2
-#define EOS_CELL_MTYPE_SMS_MSG_NEW 3
-#define EOS_CELL_MTYPE_SMS_MSG_ITEM 4
+#define EOS_CELL_MTYPE_SMS_MSG 1
+#define EOS_CELL_MTYPE_SMS_LIST 2
+#define EOS_CELL_MTYPE_SMS_LIST_ITEM 3
#define EOS_CELL_MTYPE_USSD_REQUEST 1
#define EOS_CELL_MTYPE_USSD_REPLY 2
@@ -62,7 +61,8 @@
#define EOS_CELL_PDP_SIZE_ARG 64
#define EOS_CELL_MAX_USSD_STR 128
-#define EOS_CELL_MAX_DIAL_STR 128
+#define EOS_CELL_MAX_DIAL_STR 16
+#define EOS_CELL_MAX_SMS_TEXT 160
void eos_cell_init(void);
void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler);
@@ -80,3 +80,6 @@ int eos_cell_voice_dial(char *num, unsigned char *buffer, int sync);
int eos_cell_voice_answer(unsigned char *buffer, int sync);
int eos_cell_voice_hangup(unsigned char *buffer, int sync);
unsigned char *eos_cell_voice_pcm_buffer(uint16_t *offset);
+int eos_cell_sms_send(char *num, char *text, unsigned char *buffer, int sync);
+int eos_cell_sms_recv(unsigned char *buffer, uint16_t len, char *num, uint16_t num_size, char *text, uint16_t text_size);
+int eos_cell_sms_parse(unsigned char *buffer, uint16_t len, char **num, uint16_t *num_len, char **text, uint16_t *text_len);