+/*
+ * uqmi -- tiny QMI support implementation
+ *
+ * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
#include "qmi-message.h"
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define CEILDIV(x,y) (((x) + (y) - 1) / (y))
+
static void cmd_wms_list_messages_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_wms_list_messages_response res;
fprintf(stderr, " %02x", c);
dest += len;
if (*escape) {
+ *escape = false;
switch(c) {
case 0x0A:
*dest = 0x0C;
break;
switch (type) {
- case 0:
+ case 0x00:
blobmsg_add_u32(&status, "concat_ref", (uint32_t) val[0]);
blobmsg_add_u32(&status, "concat_part", (uint32_t) val[2]);
blobmsg_add_u32(&status, "concat_parts", (uint32_t) val[1]);
break;
+ case 0x08:
+ blobmsg_add_u32(&status, "concat_ref", (uint32_t) (val[0] << 8 | val[1]));
+ blobmsg_add_u32(&status, "concat_part", (uint32_t) val[3]);
+ blobmsg_add_u32(&status, "concat_parts", (uint32_t) val[2]);
+ break;
default:
break;
}
static void decode_7bit_field(char *name, const unsigned char *data, int data_len, int bit_offset)
{
- char *dest = blobmsg_alloc_string_buffer(&status, name, 3 * (data_len * 8 / 7) + 2);
- pdu_decode_7bit_str(dest, data, data_len, bit_offset);
+ char *dest = blobmsg_alloc_string_buffer(&status, name, 3 * data_len + 2);
+ pdu_decode_7bit_str(dest, data, CEILDIV(data_len * 7, 8), bit_offset);
+ dest[data_len] = 0;
blobmsg_add_string_buffer(&status);
}
blobmsg_add_string_buffer(&status);
}
+static void blobmsg_add_hex(struct blob_buf *buf, const char *name, unsigned const char *data, int len)
+{
+ char* str = blobmsg_alloc_string_buffer(buf, name, len * 2 + 1);
+ for (int i = 0; i < len; i++) {
+ str += sprintf(str, "%02x", data[i]);
+ }
+ blobmsg_add_string_buffer(buf);
+}
+
#define cmd_wms_delete_message_cb no_cb
static enum qmi_cmd_result
cmd_wms_delete_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
/* Data Encoding */
dcs = *(data++);
- /* only 7-bit encoding supported for now */
- if (dcs & 0x0c)
- goto error;
-
if (dcs & 0x10)
blobmsg_add_u32(&status, "class", (dcs & 3));
data += 7;
}
- data++;
+ int message_len = *(data++);
+ int udh_len = 0;
int bit_offset = 0;
/* User Data Header */
if (first & 0x40) {
- int udh_len = decode_udh(data);
+ udh_len = decode_udh(data);
data += udh_len;
bit_offset = udh_len % 7;
}
if (data >= end)
goto error;
- decode_7bit_field("text", data, end - data, bit_offset);
- blobmsg_close_table(&status, c);
+ switch(dcs & 0x0c) {
+ case 0x00:
+ /* 7 bit GSM alphabet */
+ message_len = message_len - CEILDIV(udh_len * 8, 7);
+ message_len = MIN(message_len, CEILDIV((end - data) * 8, 7));
+ decode_7bit_field("text", data, message_len, bit_offset);
+ break;
+ case 0x04:
+ /* 8 bit data */
+ message_len = MIN(message_len - udh_len, end - data);
+ blobmsg_add_hex(&status, "data", data, message_len);
+ break;
+ case 0x08:
+ /* 16 bit UCS-2 string */
+ message_len = MIN(message_len - udh_len, end - data);
+ blobmsg_add_hex(&status, "ucs-2", data, message_len);
+ break;
+ default:
+ goto error;
+ }
+ blobmsg_close_table(&status, c);
return;
error:
str++;
}
- return len;
+ return lower ? len : (len + 1);
}
static int
}
for (i = 0; str[i]; i++) {
- if (str[i] >= '0' || str[i] <= '9')
+ if (str[i] >= '0' && str[i] <= '9')
continue;
ascii = true;
dest[len++] = 0;
len += pdu_encode_7bit_str(&dest[len], str);
- dest[0] = len - 1;
+ dest[0] = strlen(str);
return len;
}
unsigned char protocol_id = 0x00;
unsigned char dcs = 0x00;
- if (!_send.smsc || !*_send.smsc || !_send.target || !*_send.target) {
+ if (!_send.target || !*_send.target) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
- if (strlen(_send.smsc) > 16 || strlen(_send.target) > 16 || strlen(arg) > 160) {
+ if ((_send.smsc && strlen(_send.smsc) > 16) || strlen(_send.target) > 16 || strlen(arg) > 160) {
uqmi_add_error("Argument too long");
return QMI_CMD_EXIT;
}
if (_send.flash)
dcs |= 0x10;
- cur += pdu_encode_number(cur, _send.smsc, true);
+ if (!_send.smsc || !*_send.smsc)
+ *(cur++) = 0;
+ else
+ cur += pdu_encode_number(cur, _send.smsc, true);
+
*(cur++) = first_octet;
*(cur++) = 0; /* reference */