+/*
+ * 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 struct qmi_wms_list_messages_request lmreq = {
+ QMI_INIT(storage_type, QMI_WMS_STORAGE_TYPE_UIM),
+ QMI_INIT(message_tag, QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ),
+};
+
+static struct qmi_wms_delete_request dmreq = {
+ QMI_INIT(memory_storage, QMI_WMS_STORAGE_TYPE_UIM),
+ QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
+};
+
+static struct qmi_wms_raw_read_request gmreq = {
+ QMI_INIT_SEQUENCE(message_memory_storage_id,
+ .storage_type = QMI_WMS_STORAGE_TYPE_UIM,
+ ),
+ QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
+};
+
+
+#define cmd_wms_storage_cb no_cb
+static enum qmi_cmd_result
+cmd_wms_storage_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+ if (strcmp(arg, "sim") == 0) {
+ } else if (strcmp(arg, "me") == 0) {
+ qmi_set_ptr(&lmreq, storage_type, QMI_WMS_STORAGE_TYPE_NV);
+ qmi_set_ptr(&dmreq, memory_storage, QMI_WMS_STORAGE_TYPE_NV);
+ qmi_set_ptr(&gmreq, message_memory_storage_id.storage_type, QMI_WMS_STORAGE_TYPE_NV);
+ } else {
+ uqmi_add_error("Invalid value (sim or me)");
+ return QMI_CMD_EXIT;
+ }
+ return QMI_CMD_DONE;
+}
+
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;
static enum qmi_cmd_result
cmd_wms_list_messages_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- static struct qmi_wms_list_messages_request mreq = {
- QMI_INIT(storage_type, QMI_WMS_STORAGE_TYPE_UIM),
- QMI_INIT(message_tag, QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ),
- };
-
- qmi_set_wms_list_messages_request(msg, &mreq);
+ qmi_set_wms_list_messages_request(msg, &lmreq);
return QMI_CMD_REQUEST;
}
fprintf(stderr, " %02x", c);
dest += len;
if (*escape) {
+ *escape = false;
switch(c) {
case 0x0A:
*dest = 0x0C;
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 + 2);
- pdu_decode_7bit_str(dest, data, CEILDIV(data_len * 7, 8), bit_offset);
- dest[data_len] = 0;
+ int out_len = pdu_decode_7bit_str(dest, data, CEILDIV(data_len * 7, 8), bit_offset);
+ dest[out_len] = 0;
blobmsg_add_string_buffer(&status);
}
return QMI_CMD_EXIT;
}
- static struct qmi_wms_delete_request mreq = {
- QMI_INIT(memory_storage, QMI_WMS_STORAGE_TYPE_UIM),
- QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
- };
-
- mreq.set.memory_index = 1;
- mreq.data.memory_index = id;
+ dmreq.set.memory_index = 1;
+ dmreq.data.memory_index = id;
- qmi_set_wms_delete_request(msg, &mreq);
+ qmi_set_wms_delete_request(msg, &dmreq);
return QMI_CMD_REQUEST;
}
static enum qmi_cmd_result
cmd_wms_get_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- static struct qmi_wms_raw_read_request mreq = {
- QMI_INIT_SEQUENCE(message_memory_storage_id,
- .storage_type = QMI_WMS_STORAGE_TYPE_UIM,
- ),
- QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
- };
char *err;
int id;
return QMI_CMD_EXIT;
}
- mreq.data.message_memory_storage_id.memory_index = id;
- qmi_set_wms_raw_read_request(msg, &mreq);
+ gmreq.data.message_memory_storage_id.memory_index = id;
+ qmi_set_wms_raw_read_request(msg, &gmreq);
return QMI_CMD_REQUEST;
}
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 */