1 #include "qmi-message.h"
3 static struct qmi_nas_set_system_selection_preference_request sel_req;
5 #define cmd_nas_do_set_system_selection_cb no_cb
6 static enum qmi_cmd_result
7 cmd_nas_do_set_system_selection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
9 qmi_set_nas_set_system_selection_preference_request(msg, &sel_req);
10 return QMI_CMD_REQUEST;
13 static enum qmi_cmd_result
16 static bool use_sel_req = false;
20 uqmi_add_command(NULL, __UQMI_COMMAND_nas_do_set_system_selection);
26 #define cmd_nas_set_network_modes_cb no_cb
27 static enum qmi_cmd_result
28 cmd_nas_set_network_modes_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
32 QmiNasRatModePreference val;
34 { "cdma", QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1X | QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1XEVDO },
35 { "td-scdma", QMI_NAS_RAT_MODE_PREFERENCE_TD_SCDMA },
36 { "gsm", QMI_NAS_RAT_MODE_PREFERENCE_GSM },
37 { "umts", QMI_NAS_RAT_MODE_PREFERENCE_UMTS },
38 { "lte", QMI_NAS_RAT_MODE_PREFERENCE_LTE },
40 QmiNasRatModePreference val = 0;
44 for (word = strtok(arg, ",");
46 word = strtok(NULL, ",")) {
49 for (i = 0; i < ARRAY_SIZE(modes); i++) {
50 if (strcmp(word, modes[i].name) != 0 &&
51 strcmp(word, "all") != 0)
59 uqmi_add_error("Invalid network mode");
64 qmi_set(&sel_req, mode_preference, val);
65 return do_sel_network();
68 #define cmd_nas_set_network_preference_cb no_cb
69 static enum qmi_cmd_result
70 cmd_nas_set_network_preference_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
72 QmiNasGsmWcdmaAcquisitionOrderPreference pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC;
74 if (!strcmp(arg, "gsm"))
75 pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_GSM;
76 else if (!strcmp(arg, "wcdma"))
77 pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_WCDMA;
79 qmi_set(&sel_req, gsm_wcdma_acquisition_order_preference, pref);
80 return do_sel_network();
83 #define cmd_nas_set_roaming_cb no_cb
84 static enum qmi_cmd_result
85 cmd_nas_set_roaming_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
87 QmiNasRoamingPreference pref;
89 if (!strcmp(arg, "any"))
90 pref = QMI_NAS_ROAMING_PREFERENCE_ANY;
91 else if (!strcmp(arg, "only"))
92 pref = QMI_NAS_ROAMING_PREFERENCE_NOT_OFF;
93 else if (!strcmp(arg, "off"))
94 pref = QMI_NAS_ROAMING_PREFERENCE_OFF;
96 return uqmi_add_error("Invalid argument");
98 qmi_set(&sel_req, roaming_preference, pref);
99 return do_sel_network();
102 #define cmd_nas_initiate_network_register_cb no_cb
103 static enum qmi_cmd_result
104 cmd_nas_initiate_network_register_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
106 static struct qmi_nas_initiate_network_register_request register_req = {
107 QMI_INIT(action, QMI_NAS_NETWORK_REGISTER_TYPE_AUTOMATIC)
110 qmi_set_nas_initiate_network_register_request(msg, ®ister_req);
111 return QMI_CMD_REQUEST;
115 cmd_nas_get_signal_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
117 struct qmi_nas_get_signal_info_response res;
120 qmi_parse_nas_get_signal_info_response(msg, &res);
122 c = blobmsg_open_table(&status, NULL);
123 if (res.set.cdma_signal_strength) {
124 blobmsg_add_string(&status, "type", "cdma");
125 blobmsg_add_u32(&status, "rssi", (int32_t) res.data.cdma_signal_strength.rssi);
126 blobmsg_add_u32(&status, "ecio", (int32_t) res.data.cdma_signal_strength.ecio);
129 if (res.set.hdr_signal_strength) {
130 blobmsg_add_string(&status, "type", "hdr");
131 blobmsg_add_u32(&status, "rssi", (int32_t) res.data.hdr_signal_strength.rssi);
132 blobmsg_add_u32(&status, "ecio", (int32_t) res.data.hdr_signal_strength.ecio);
133 blobmsg_add_u32(&status, "io", res.data.hdr_signal_strength.io);
136 if (res.set.gsm_signal_strength) {
137 blobmsg_add_string(&status, "type", "gsm");
138 blobmsg_add_u32(&status, "signal", (int32_t) res.data.gsm_signal_strength);
141 if (res.set.wcdma_signal_strength) {
142 blobmsg_add_string(&status, "type", "wcdma");
143 blobmsg_add_u32(&status, "rssi", (int32_t) res.data.wcdma_signal_strength.rssi);
144 blobmsg_add_u32(&status, "ecio", (int32_t) res.data.wcdma_signal_strength.ecio);
147 if (res.set.lte_signal_strength) {
148 blobmsg_add_string(&status, "type", "lte");
149 blobmsg_add_u32(&status, "rssi", (int32_t) res.data.lte_signal_strength.rssi);
150 blobmsg_add_u32(&status, "rsrq", (int32_t) res.data.lte_signal_strength.rsrq);
151 blobmsg_add_u32(&status, "rsrp", (int32_t) res.data.lte_signal_strength.rsrp);
152 blobmsg_add_u32(&status, "snr", (int32_t) res.data.lte_signal_strength.snr);
155 if (res.set.tdma_signal_strength) {
156 blobmsg_add_string(&status, "type", "tdma");
157 blobmsg_add_u32(&status, "signal", (int32_t) res.data.tdma_signal_strength);
160 blobmsg_close_table(&status, c);
163 static enum qmi_cmd_result
164 cmd_nas_get_signal_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
166 qmi_set_nas_get_signal_info_request(msg);
167 return QMI_CMD_REQUEST;
171 cmd_nas_get_serving_system_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
173 struct qmi_nas_get_serving_system_response res;
174 static const char *reg_states[] = {
175 [QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED] = "not_registered",
176 [QMI_NAS_REGISTRATION_STATE_REGISTERED] = "registered",
177 [QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED_SEARCHING] = "searching",
178 [QMI_NAS_REGISTRATION_STATE_REGISTRATION_DENIED] = "registering_denied",
179 [QMI_NAS_REGISTRATION_STATE_UNKNOWN] = "unknown",
183 qmi_parse_nas_get_serving_system_response(msg, &res);
185 c = blobmsg_open_table(&status, NULL);
186 if (res.set.serving_system) {
187 int state = res.data.serving_system.registration_state;
189 if (state > QMI_NAS_REGISTRATION_STATE_UNKNOWN)
190 state = QMI_NAS_REGISTRATION_STATE_UNKNOWN;
192 blobmsg_add_string(&status, "registration", reg_states[state]);
194 if (res.set.current_plmn) {
195 blobmsg_add_u32(&status, "plmn_mcc", res.data.current_plmn.mcc);
196 blobmsg_add_u32(&status, "plmn_mnc", res.data.current_plmn.mnc);
197 if (res.data.current_plmn.description)
198 blobmsg_add_string(&status, "plmn_description", res.data.current_plmn.description);
201 if (res.set.roaming_indicator)
202 blobmsg_add_u8(&status, "roaming", !res.data.roaming_indicator);
204 blobmsg_close_table(&status, c);
207 static enum qmi_cmd_result
208 cmd_nas_get_serving_system_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
210 qmi_set_nas_get_serving_system_request(msg);
211 return QMI_CMD_REQUEST;
215 cmd_nas_network_scan_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
217 static struct qmi_nas_network_scan_response res;
218 const char *network_status[] = {
228 const char *radio[] = {
229 [QMI_NAS_RADIO_INTERFACE_NONE] = "none",
230 [QMI_NAS_RADIO_INTERFACE_CDMA_1X] = "cdma-1x",
231 [QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO] = "cdma-1x_evdo",
232 [QMI_NAS_RADIO_INTERFACE_AMPS] = "amps",
233 [QMI_NAS_RADIO_INTERFACE_GSM] = "gsm",
234 [QMI_NAS_RADIO_INTERFACE_UMTS] = "umts",
235 [QMI_NAS_RADIO_INTERFACE_LTE] = "lte",
236 [QMI_NAS_RADIO_INTERFACE_TD_SCDMA] = "td-scdma",
238 void *t, *c, *info, *stat;
241 qmi_parse_nas_network_scan_response(msg, &res);
243 t = blobmsg_open_table(&status, NULL);
245 c = blobmsg_open_array(&status, "network_info");
246 for (i = 0; i < res.data.network_information_n; i++) {
247 info = blobmsg_open_table(&status, NULL);
248 blobmsg_add_u32(&status, "mcc", res.data.network_information[i].mcc);
249 blobmsg_add_u32(&status, "mnc", res.data.network_information[i].mnc);
250 if (res.data.network_information[i].description)
251 blobmsg_add_string(&status, "description", res.data.network_information[i].description);
252 stat = blobmsg_open_array(&status, "status");
253 for (j = 0; j < ARRAY_SIZE(network_status); j++) {
254 if (!(res.data.network_information[i].network_status & (1 << j)))
257 blobmsg_add_string(&status, NULL, network_status[j]);
259 blobmsg_close_array(&status, stat);
260 blobmsg_close_table(&status, info);
262 blobmsg_close_array(&status, c);
264 c = blobmsg_open_array(&status, "radio_access_technology");
265 for (i = 0; i < res.data.radio_access_technology_n; i++) {
266 const char *r = "unknown";
267 int r_i = res.data.radio_access_technology[i].radio_interface;
269 info = blobmsg_open_table(&status, NULL);
270 blobmsg_add_u32(&status, "mcc", res.data.radio_access_technology[i].mcc);
271 blobmsg_add_u32(&status, "mnc", res.data.radio_access_technology[i].mnc);
272 if (r_i >= 0 && r_i < ARRAY_SIZE(radio))
275 blobmsg_add_string(&status, "radio", r);
276 blobmsg_close_table(&status, info);
278 blobmsg_close_array(&status, c);
280 blobmsg_close_table(&status, t);
283 static enum qmi_cmd_result
284 cmd_nas_network_scan_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
286 struct qmi_nas_network_scan_request sreq = {};
288 qmi_set_nas_network_scan_request(msg, &sreq);
289 return QMI_CMD_REQUEST;