From 30035f2753217507227f21d22e394cf85f7cdbfd Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Mon, 24 Oct 2022 19:53:12 +0200 Subject: added cell sms support --- fw/fe310/eos/net/cell.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'fw/fe310/eos/net/cell.c') 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; +} -- cgit v1.2.3