static void cmd_dms_get_pin_status_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_uim_get_pin_status_response res;
+ void *c;
qmi_parse_dms_uim_get_pin_status_response(msg, &res);
+ c = blobmsg_open_table(&status, NULL);
if (res.set.pin1_status) {
blobmsg_add_string(&status, "pin1_status", get_pin_status(res.data.pin1_status.current_status));
blobmsg_add_u32(&status, "pin1_verify_tries", (int32_t) res.data.pin1_status.verify_retries_left);
blobmsg_add_u32(&status, "pin2_verify_tries", (int32_t) res.data.pin2_status.verify_retries_left);
blobmsg_add_u32(&status, "pin2_unblock_tries", (int32_t) res.data.pin2_status.unblock_retries_left);
}
+ blobmsg_close_table(&status, c);
}
static enum qmi_cmd_result
qmi_parse_dms_uim_get_imsi_response(msg, &res);
if (res.data.imsi)
- blobmsg_add_string(&status, "number", res.data.imsi);
+ blobmsg_add_string(&status, NULL, res.data.imsi);
}
static enum qmi_cmd_result
}
if (!found) {
- blobmsg_add_string(&status, "error", "Invalid network mode");
+ uqmi_add_error("Invalid network mode");
return QMI_CMD_EXIT;
}
}
cmd_nas_get_signal_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_nas_get_signal_info_response res;
+ void *c;
qmi_parse_nas_get_signal_info_response(msg, &res);
+ c = blobmsg_open_table(&status, NULL);
if (res.set.cdma_signal_strength) {
blobmsg_add_string(&status, "type", "cdma");
blobmsg_add_u32(&status, "rssi", (int32_t) res.data.cdma_signal_strength.rssi);
blobmsg_add_u32(&status, "rsrp", (int32_t) res.data.lte_signal_strength.rsrp);
blobmsg_add_u32(&status, "snr", (int32_t) res.data.lte_signal_strength.snr);
}
+
+ blobmsg_close_table(&status, c);
}
static enum qmi_cmd_result
[QMI_NAS_REGISTRATION_STATE_REGISTRATION_DENIED] = "registering_denied",
[QMI_NAS_REGISTRATION_STATE_UNKNOWN] = "unknown",
};
+ void *c;
qmi_parse_nas_get_serving_system_response(msg, &res);
+ c = blobmsg_open_table(&status, NULL);
if (res.set.serving_system) {
int state = res.data.serving_system.registration_state;
if (res.set.roaming_indicator)
blobmsg_add_u8(&status, "roaming", !res.data.roaming_indicator);
+
+ blobmsg_close_table(&status, c);
}
static enum qmi_cmd_result
return QMI_CMD_DONE;
}
- blobmsg_add_string(&status, "error", "Invalid auth mode (valid: pap, chap, both, none)");
+ uqmi_add_error("Invalid auth mode (valid: pap, chap, both, none)");
return QMI_CMD_EXIT;
}
qmi_parse_wds_start_network_response(msg, &res);
if (res.set.packet_data_handle)
- blobmsg_add_u32(&status, "handle", res.data.packet_data_handle);
+ blobmsg_add_u32(&status, NULL, res.data.packet_data_handle);
}
static enum qmi_cmd_result
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;
- int i, len = 0;
+ void *c;
+ int i;
qmi_parse_wms_list_messages_response(msg, &res);
- blobmsg_alloc_string_buffer(&status, "messages", 1);
- for (i = 0; i < res.data.message_list_n; i++) {
- len += sprintf(blobmsg_realloc_string_buffer(&status, len + 12) + len,
- " %d" + (len ? 0 : 1),
- res.data.message_list[i].memory_index);
- }
- blobmsg_add_string_buffer(&status);
+ c = blobmsg_open_array(&status, NULL);
+ for (i = 0; i < res.data.message_list_n; i++)
+ blobmsg_add_u32(&status, NULL, res.data.message_list[i].memory_index);
+
+ blobmsg_close_array(&status, c);
}
static enum qmi_cmd_result
int cur_len;
bool sent;
unsigned char first, dcs;
+ void *c;
qmi_parse_wms_raw_read_response(msg, &res);
+ c = blobmsg_open_table(&status, NULL);
data = (unsigned char *) res.data.raw_message_data.raw_data;
end = data + res.data.raw_message_data.raw_data_n;
cur_len = *(data++);
decode_7bit_field("text", data, end - data, !!(first & 0x40));
+ blobmsg_close_table(&status, c);
}
static enum qmi_cmd_result
id = strtoul(arg, &err, 10);
if (err && *err) {
- blobmsg_add_string(&status, "error", "Invalid message ID");
+ uqmi_add_error("Invalid message ID");
return QMI_CMD_EXIT;
}
qmi_parse_wms_raw_read_response(msg, &res);
data = (unsigned char *) res.data.raw_message_data.raw_data;
- str = blobmsg_alloc_string_buffer(&status, "data", res.data.raw_message_data.raw_data_n * 3);
+ str = blobmsg_alloc_string_buffer(&status, NULL, res.data.raw_message_data.raw_data_n * 3);
for (i = 0; i < res.data.raw_message_data.raw_data_n; i++) {
str += sprintf(str, " %02x" + (i ? 0 : 1), data[i]);
}
unsigned char dcs = 0x00;
if (!send.smsc || !*send.smsc || !send.target || !*send.target) {
- blobmsg_add_string(&status, "error", "Missing argument");
+ uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
if (strlen(send.smsc) > 16 || strlen(send.target) > 16 || strlen(arg) > 160) {
- blobmsg_add_string(&status, "error", "Argument too long");
+ uqmi_add_error("Argument too long");
return QMI_CMD_EXIT;
}
{
char *str;
- str = blobmsg_format_json_indent(data, true, 0);
+ if (!blob_len(data))
+ return;
+
+ str = blobmsg_format_json_indent(blob_data(data), false, 0);
if (!str)
return;
blob_buf_init(&status, 0);
if (cmds[i].handler->type > QMI_SERVICE_CTL &&
qmi_service_connect(qmi, cmds[i].handler->type, -1)) {
- blobmsg_printf(&status, "error", "failed to connect to service");
+ uqmi_add_error("Failed to connect to service");
res = QMI_CMD_EXIT;
} else {
res = cmds[i].handler->prepare(qmi, &req, (void *) buf, cmds[i].arg);
if (res == QMI_CMD_REQUEST) {
qmi_request_start(qmi, &req, (void *) buf, cmds[i].handler->cb);
req.no_error_cb = true;
- if (qmi_request_wait(qmi, &req))
- blobmsg_add_string(&status, "error", qmi_get_error_str(req.ret));
+ if (qmi_request_wait(qmi, &req)) {
+ uqmi_add_error(qmi_get_error_str(req.ret));
+ do_break = true;
+ }
} else if (res == QMI_CMD_EXIT) {
do_break = true;
}
return true;
}
-void uqmi_run_commands(struct qmi_dev *qmi)
+void uqmi_add_error(const char *msg)
+{
+ blobmsg_add_string(&status, NULL, msg);
+}
+
+bool uqmi_run_commands(struct qmi_dev *qmi)
{
- if (__uqmi_run_commands(qmi, true))
- __uqmi_run_commands(qmi, false);
+ bool ret;
+
+ ret = __uqmi_run_commands(qmi, true) &&
+ __uqmi_run_commands(qmi, false);
+
free(cmds);
cmds = NULL;
n_cmds = 0;
+
+ return ret;
}
extern const struct uqmi_cmd_handler uqmi_cmd_handler[];
void uqmi_add_command(char *arg, int longidx);
-void uqmi_run_commands(struct qmi_dev *qmi);
+bool uqmi_run_commands(struct qmi_dev *qmi);
+void uqmi_add_error(const char *msg);
#endif
int main(int argc, char **argv)
{
static struct qmi_dev dev;
- int ch;
+ int ch, ret;
uloop_init();
signal(SIGINT, handle_exit_signal);
return 2;
}
- uqmi_run_commands(&dev);
+ ret = uqmi_run_commands(&dev) ? 0 : -1;
qmi_device_close(&dev);
- return 0;
+ return ret;
}