commands-nas.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. /*
  2. * uqmi -- tiny QMI support implementation
  3. *
  4. * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA.
  20. */
  21. #include "qmi-message.h"
  22. static struct qmi_nas_get_tx_rx_info_request tx_rx_req;
  23. static struct qmi_nas_set_system_selection_preference_request sel_req;
  24. static struct {
  25. bool mcc_is_set;
  26. bool mnc_is_set;
  27. } plmn_code_flag;
  28. static void
  29. print_earfcn_info(uint32_t earfcn)
  30. {
  31. /* https://www.sqimway.com/lte_band.php */
  32. static const struct {
  33. uint32_t min;
  34. uint32_t max;
  35. uint16_t band;
  36. uint16_t freq;
  37. const char *duplex;
  38. } earfcn_ranges[] = {
  39. { 0, 599, 1, 2100, "FDD" },
  40. { 600, 1199, 2, 1800, "FDD" },
  41. { 1200, 1949, 3, 1800, "FDD" },
  42. { 1950, 2399, 4, 1700, "FDD" },
  43. { 2400, 2649, 5, 850, "FDD" },
  44. { 2650, 2749, 6, 800, "FDD" },
  45. { 2750, 3449, 7, 2600, "FDD" },
  46. { 3450, 3799, 8, 900, "FDD" },
  47. { 3800, 4149, 9, 1800, "FDD" },
  48. { 4150, 4749, 10, 1700, "FDD" },
  49. { 4750, 4999, 11, 1500, "FDD" },
  50. { 5000, 5179, 12, 700, "FDD" },
  51. { 5180, 5279, 13, 700, "FDD" },
  52. { 5280, 5379, 14, 700, "FDD" },
  53. { 5730, 5849, 17, 700, "FDD" },
  54. { 5850, 5999, 18, 850, "FDD" },
  55. { 6000, 6149, 19, 850, "FDD" },
  56. { 6150, 6449, 20, 800, "FDD" },
  57. { 6450, 6599, 21, 1500, "FDD" },
  58. { 6600, 7399, 22, 3500, "FDD" },
  59. { 7500, 7699, 23, 2000, "FDD" },
  60. { 7700, 8039, 24, 1600, "FDD" },
  61. { 8040, 8689, 25, 1900, "FDD" },
  62. { 8690, 9039, 26, 850, "FDD" },
  63. { 9040, 9209, 27, 800, "FDD" },
  64. { 9210, 9659, 28, 700, "FDD" },
  65. { 9660, 9769, 29, 700, "SDL" },
  66. { 9770, 9869, 30, 2300, "FDD" },
  67. { 9870, 9919, 31, 450, "FDD" },
  68. { 9920, 10359, 32, 1500, "SDL" },
  69. { 36000, 36199, 33, 1900, "TDD" },
  70. { 36200, 36349, 34, 2000, "TDD" },
  71. { 36350, 36949, 35, 1900, "TDD" },
  72. { 36950, 37549, 36, 1900, "TDD" },
  73. { 37550, 37749, 37, 1900, "TDD" },
  74. { 37750, 38249, 38, 2600, "TDD" },
  75. { 38250, 38649, 39, 1900, "TDD" },
  76. { 38650, 39649, 40, 2300, "TDD" },
  77. { 39650, 41589, 41, 2500, "TDD" },
  78. { 41590, 43589, 42, 3500, "TDD" },
  79. { 43590, 45589, 43, 3700, "TDD" },
  80. { 45590, 46589, 44, 700, "TDD" },
  81. };
  82. for (int i = 0; i < (sizeof(earfcn_ranges) / sizeof(*earfcn_ranges)); i++) {
  83. if (earfcn <= earfcn_ranges[i].max && earfcn >= earfcn_ranges[i].min) {
  84. blobmsg_add_u32(&status, "band", earfcn_ranges[i].band);
  85. blobmsg_add_u32(&status, "frequency", earfcn_ranges[i].freq);
  86. blobmsg_add_string(&status, "duplex", earfcn_ranges[i].duplex);
  87. return;
  88. }
  89. }
  90. }
  91. #define cmd_nas_do_set_system_selection_cb no_cb
  92. static enum qmi_cmd_result
  93. cmd_nas_do_set_system_selection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  94. {
  95. qmi_set_nas_set_system_selection_preference_request(msg, &sel_req);
  96. return QMI_CMD_REQUEST;
  97. }
  98. static enum qmi_cmd_result
  99. do_sel_network(void)
  100. {
  101. static bool use_sel_req = false;
  102. if (!use_sel_req) {
  103. use_sel_req = true;
  104. uqmi_add_command(NULL, __UQMI_COMMAND_nas_do_set_system_selection);
  105. }
  106. return QMI_CMD_DONE;
  107. }
  108. #define cmd_nas_set_network_modes_cb no_cb
  109. static enum qmi_cmd_result
  110. cmd_nas_set_network_modes_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  111. {
  112. static const struct {
  113. const char *name;
  114. QmiNasRatModePreference val;
  115. } modes[] = {
  116. { "cdma", QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1X | QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1XEVDO },
  117. { "td-scdma", QMI_NAS_RAT_MODE_PREFERENCE_TD_SCDMA },
  118. { "gsm", QMI_NAS_RAT_MODE_PREFERENCE_GSM },
  119. { "umts", QMI_NAS_RAT_MODE_PREFERENCE_UMTS },
  120. { "lte", QMI_NAS_RAT_MODE_PREFERENCE_LTE },
  121. };
  122. QmiNasRatModePreference val = 0;
  123. char *word;
  124. int i;
  125. for (word = strtok(arg, ",");
  126. word;
  127. word = strtok(NULL, ",")) {
  128. bool found = false;
  129. for (i = 0; i < ARRAY_SIZE(modes); i++) {
  130. if (strcmp(word, modes[i].name) != 0 &&
  131. strcmp(word, "all") != 0)
  132. continue;
  133. val |= modes[i].val;
  134. found = true;
  135. }
  136. if (!found) {
  137. uqmi_add_error("Invalid network mode");
  138. return QMI_CMD_EXIT;
  139. }
  140. }
  141. qmi_set(&sel_req, mode_preference, val);
  142. return do_sel_network();
  143. }
  144. #define cmd_nas_set_network_preference_cb no_cb
  145. static enum qmi_cmd_result
  146. cmd_nas_set_network_preference_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  147. {
  148. QmiNasGsmWcdmaAcquisitionOrderPreference pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC;
  149. if (!strcmp(arg, "gsm"))
  150. pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_GSM;
  151. else if (!strcmp(arg, "wcdma"))
  152. pref = QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_WCDMA;
  153. qmi_set(&sel_req, gsm_wcdma_acquisition_order_preference, pref);
  154. return do_sel_network();
  155. }
  156. #define cmd_nas_set_roaming_cb no_cb
  157. static enum qmi_cmd_result
  158. cmd_nas_set_roaming_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  159. {
  160. QmiNasRoamingPreference pref;
  161. if (!strcmp(arg, "any"))
  162. pref = QMI_NAS_ROAMING_PREFERENCE_ANY;
  163. else if (!strcmp(arg, "only"))
  164. pref = QMI_NAS_ROAMING_PREFERENCE_NOT_OFF;
  165. else if (!strcmp(arg, "off"))
  166. pref = QMI_NAS_ROAMING_PREFERENCE_OFF;
  167. else
  168. return uqmi_add_error("Invalid argument");
  169. qmi_set(&sel_req, roaming_preference, pref);
  170. return do_sel_network();
  171. }
  172. #define cmd_nas_set_mcc_cb no_cb
  173. static enum qmi_cmd_result
  174. cmd_nas_set_mcc_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  175. {
  176. char *err;
  177. int value = strtoul(arg, &err, 10);
  178. if (err && *err) {
  179. uqmi_add_error("Invalid MCC value");
  180. return QMI_CMD_EXIT;
  181. }
  182. sel_req.data.network_selection_preference.mcc = value;
  183. plmn_code_flag.mcc_is_set = true;
  184. return QMI_CMD_DONE;
  185. }
  186. #define cmd_nas_set_mnc_cb no_cb
  187. static enum qmi_cmd_result
  188. cmd_nas_set_mnc_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  189. {
  190. char *err;
  191. int value = strtoul(arg, &err, 10);
  192. if (err && *err) {
  193. uqmi_add_error("Invalid MNC value");
  194. return QMI_CMD_EXIT;
  195. }
  196. sel_req.data.network_selection_preference.mnc = value;
  197. plmn_code_flag.mnc_is_set = true;
  198. return QMI_CMD_DONE;
  199. }
  200. #define cmd_nas_set_plmn_cb no_cb
  201. static enum qmi_cmd_result
  202. cmd_nas_set_plmn_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  203. {
  204. sel_req.set.network_selection_preference = 1;
  205. sel_req.data.network_selection_preference.mode = QMI_NAS_NETWORK_SELECTION_PREFERENCE_AUTOMATIC;
  206. if (!plmn_code_flag.mcc_is_set && plmn_code_flag.mnc_is_set) {
  207. uqmi_add_error("No MCC value");
  208. return QMI_CMD_EXIT;
  209. }
  210. if (plmn_code_flag.mcc_is_set && sel_req.data.network_selection_preference.mcc) {
  211. if (!plmn_code_flag.mnc_is_set) {
  212. uqmi_add_error("No MNC value");
  213. return QMI_CMD_EXIT;
  214. } else {
  215. sel_req.data.network_selection_preference.mode = QMI_NAS_NETWORK_SELECTION_PREFERENCE_MANUAL;
  216. }
  217. }
  218. return do_sel_network();
  219. }
  220. #define cmd_nas_initiate_network_register_cb no_cb
  221. static enum qmi_cmd_result
  222. cmd_nas_initiate_network_register_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  223. {
  224. static struct qmi_nas_initiate_network_register_request register_req = {
  225. QMI_INIT(action, QMI_NAS_NETWORK_REGISTER_TYPE_AUTOMATIC)
  226. };
  227. qmi_set_nas_initiate_network_register_request(msg, &register_req);
  228. return QMI_CMD_REQUEST;
  229. }
  230. static void
  231. cmd_nas_get_signal_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  232. {
  233. struct qmi_nas_get_signal_info_response res;
  234. void *c;
  235. qmi_parse_nas_get_signal_info_response(msg, &res);
  236. c = blobmsg_open_table(&status, NULL);
  237. if (res.set.cdma_signal_strength) {
  238. blobmsg_add_string(&status, "type", "cdma");
  239. blobmsg_add_u32(&status, "rssi", (int32_t) res.data.cdma_signal_strength.rssi);
  240. blobmsg_add_u32(&status, "ecio", (int32_t) res.data.cdma_signal_strength.ecio);
  241. }
  242. if (res.set.hdr_signal_strength) {
  243. blobmsg_add_string(&status, "type", "hdr");
  244. blobmsg_add_u32(&status, "rssi", (int32_t) res.data.hdr_signal_strength.rssi);
  245. blobmsg_add_u32(&status, "ecio", (int32_t) res.data.hdr_signal_strength.ecio);
  246. blobmsg_add_u32(&status, "io", res.data.hdr_signal_strength.io);
  247. }
  248. if (res.set.gsm_signal_strength) {
  249. blobmsg_add_string(&status, "type", "gsm");
  250. blobmsg_add_u32(&status, "signal", (int32_t) res.data.gsm_signal_strength);
  251. }
  252. if (res.set.wcdma_signal_strength) {
  253. blobmsg_add_string(&status, "type", "wcdma");
  254. blobmsg_add_u32(&status, "rssi", (int32_t) res.data.wcdma_signal_strength.rssi);
  255. blobmsg_add_u32(&status, "ecio", (int32_t) res.data.wcdma_signal_strength.ecio);
  256. }
  257. if (res.set.lte_signal_strength) {
  258. blobmsg_add_string(&status, "type", "lte");
  259. blobmsg_add_u32(&status, "rssi", (int32_t) res.data.lte_signal_strength.rssi);
  260. blobmsg_add_u32(&status, "rsrq", (int32_t) res.data.lte_signal_strength.rsrq);
  261. blobmsg_add_u32(&status, "rsrp", (int32_t) res.data.lte_signal_strength.rsrp);
  262. blobmsg_add_double(&status, "snr", (double) res.data.lte_signal_strength.snr*0.1);
  263. }
  264. if (res.set.tdma_signal_strength) {
  265. blobmsg_add_string(&status, "type", "tdma");
  266. blobmsg_add_u32(&status, "signal", (int32_t) res.data.tdma_signal_strength);
  267. }
  268. blobmsg_close_table(&status, c);
  269. }
  270. static void
  271. print_system_info(uint8_t svc_status, uint8_t tsvc_status, bool preferred, bool system_info,
  272. bool domain_valid, uint8_t domain,
  273. bool service_cap_valid, uint8_t service_cap,
  274. bool roaming_status_valid, uint8_t roaming_status,
  275. bool forbidden_valid, bool forbidden,
  276. bool network_id_valid, char *mcc, char *mnc,
  277. bool lac_valid, uint16_t lac)
  278. {
  279. static const char *map_service[] = {
  280. [QMI_NAS_SERVICE_STATUS_NONE] = "none",
  281. [QMI_NAS_SERVICE_STATUS_LIMITED] = "limited",
  282. [QMI_NAS_SERVICE_STATUS_AVAILABLE] = "available",
  283. [QMI_NAS_SERVICE_STATUS_LIMITED_REGIONAL] = "limited regional",
  284. [QMI_NAS_SERVICE_STATUS_POWER_SAVE] = "power save",
  285. };
  286. static const char *map_roaming[] = {
  287. [QMI_NAS_ROAMING_STATUS_OFF] = "off",
  288. [QMI_NAS_ROAMING_STATUS_ON] = "on",
  289. [QMI_NAS_ROAMING_STATUS_BLINK] = "blink",
  290. [QMI_NAS_ROAMING_STATUS_OUT_OF_NEIGHBORHOOD] = "out of neighborhood",
  291. [QMI_NAS_ROAMING_STATUS_OUT_OF_BUILDING] = "out of building",
  292. [QMI_NAS_ROAMING_STATUS_PREFERRED_SYSTEM] = "preferred system",
  293. [QMI_NAS_ROAMING_STATUS_AVAILABLE_SYSTEM] = "available system",
  294. [QMI_NAS_ROAMING_STATUS_ALLIANCE_PARTNER] = "alliance partner",
  295. [QMI_NAS_ROAMING_STATUS_PREMIUM_PARTNER] = "premium partner",
  296. [QMI_NAS_ROAMING_STATUS_FULL_SERVICE] = "full service",
  297. [QMI_NAS_ROAMING_STATUS_PARTIAL_SERVICE] = "partial service",
  298. [QMI_NAS_ROAMING_STATUS_BANNER_ON] = "banner on",
  299. [QMI_NAS_ROAMING_STATUS_BANNER_OFF] = "banner off",
  300. };
  301. static const char *map_network[] = {
  302. [QMI_NAS_NETWORK_SERVICE_DOMAIN_NONE] = "none",
  303. [QMI_NAS_NETWORK_SERVICE_DOMAIN_CS] = "cs",
  304. [QMI_NAS_NETWORK_SERVICE_DOMAIN_PS] = "ps",
  305. [QMI_NAS_NETWORK_SERVICE_DOMAIN_CS_PS] = "cs-ps",
  306. [QMI_NAS_NETWORK_SERVICE_DOMAIN_UNKNOWN] = "unknown",
  307. };
  308. blobmsg_add_string(&status, "service_status", map_service[svc_status]);
  309. blobmsg_add_string(&status, "true_service_status", map_service[tsvc_status]);
  310. blobmsg_add_u8(&status, "preferred_data_path", preferred);
  311. if (system_info) {
  312. if (domain_valid)
  313. blobmsg_add_string(&status, "domain", map_network[domain]);
  314. if (service_cap_valid)
  315. blobmsg_add_string(&status, "service", map_network[service_cap]);
  316. if (roaming_status_valid)
  317. blobmsg_add_string(&status, "roaming_status", map_roaming[roaming_status]);
  318. if (forbidden_valid)
  319. blobmsg_add_u8(&status, "forbidden", forbidden);
  320. if (network_id_valid) {
  321. blobmsg_add_string(&status, "mcc", mcc);
  322. if ((uint8_t)mnc[2] == 255)
  323. mnc[2] = 0;
  324. blobmsg_add_string(&status, "mnc", mnc);
  325. }
  326. if (lac_valid)
  327. blobmsg_add_u32(&status, "location_area_code", (int32_t) lac);
  328. }
  329. }
  330. static void
  331. cmd_nas_get_system_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  332. {
  333. static const char *cell_status[] = {
  334. [QMI_NAS_CELL_ACCESS_STATUS_NORMAL_ONLY] = "normal",
  335. [QMI_NAS_CELL_ACCESS_STATUS_EMERGENCY_ONLY] = "emergency",
  336. [QMI_NAS_CELL_ACCESS_STATUS_NO_CALLS] = "no calls",
  337. [QMI_NAS_CELL_ACCESS_STATUS_ALL_CALLS] = "all calls",
  338. [QMI_NAS_CELL_ACCESS_STATUS_UNKNOWN] = "unknown",
  339. };
  340. struct qmi_nas_get_system_info_response res;
  341. void *c, *t;
  342. qmi_parse_nas_get_system_info_response(msg, &res);
  343. t = blobmsg_open_table(&status, NULL);
  344. if (res.set.gsm_service_status) {
  345. c = blobmsg_open_table(&status, "gsm");
  346. print_system_info(res.data.gsm_service_status.service_status,
  347. res.data.gsm_service_status.true_service_status,
  348. res.data.gsm_service_status.preferred_data_path,
  349. res.set.gsm_system_info_v2,
  350. res.data.gsm_system_info_v2.domain_valid,
  351. res.data.gsm_system_info_v2.domain,
  352. res.data.gsm_system_info_v2.service_capability_valid,
  353. res.data.gsm_system_info_v2.service_capability,
  354. res.data.gsm_system_info_v2.roaming_status_valid,
  355. res.data.gsm_system_info_v2.roaming_status,
  356. res.data.gsm_system_info_v2.forbidden_valid,
  357. res.data.gsm_system_info_v2.forbidden,
  358. res.data.gsm_system_info_v2.network_id_valid,
  359. res.data.gsm_system_info_v2.mcc,
  360. res.data.gsm_system_info_v2.mnc,
  361. res.data.gsm_system_info_v2.lac_valid,
  362. res.data.gsm_system_info_v2.lac);
  363. if (res.set.gsm_system_info_v2 && res.data.gsm_system_info_v2.cid_valid)
  364. blobmsg_add_u32(&status, "cell_id",
  365. res.data.gsm_system_info_v2.cid);
  366. if (res.set.additional_gsm_system_info &&
  367. res.data.additional_gsm_system_info.geo_system_index != 0xFFFF)
  368. blobmsg_add_u32(&status, "geo_system_index",
  369. res.data.additional_gsm_system_info.geo_system_index);
  370. blobmsg_close_table(&status, c);
  371. }
  372. if (res.set.wcdma_service_status) {
  373. c = blobmsg_open_table(&status, "wcdma");
  374. print_system_info(res.data.wcdma_service_status.service_status,
  375. res.data.wcdma_service_status.true_service_status,
  376. res.data.wcdma_service_status.preferred_data_path,
  377. res.set.wcdma_system_info_v2,
  378. res.data.wcdma_system_info_v2.domain_valid,
  379. res.data.wcdma_system_info_v2.domain,
  380. res.data.wcdma_system_info_v2.service_capability_valid,
  381. res.data.wcdma_system_info_v2.service_capability,
  382. res.data.wcdma_system_info_v2.roaming_status_valid,
  383. res.data.wcdma_system_info_v2.roaming_status,
  384. res.data.wcdma_system_info_v2.forbidden_valid,
  385. res.data.wcdma_system_info_v2.forbidden,
  386. res.data.wcdma_system_info_v2.network_id_valid,
  387. res.data.wcdma_system_info_v2.mcc,
  388. res.data.wcdma_system_info_v2.mnc,
  389. res.data.wcdma_system_info_v2.lac_valid,
  390. res.data.wcdma_system_info_v2.lac);
  391. if (res.set.wcdma_system_info_v2 && res.data.wcdma_system_info_v2.cid_valid) {
  392. blobmsg_add_u32(&status, "rnc_id",res.data.wcdma_system_info_v2.cid/65536);
  393. blobmsg_add_u32(&status, "cell_id",res.data.wcdma_system_info_v2.cid%65536);
  394. }
  395. if (res.set.additional_wcdma_system_info &&
  396. res.data.additional_wcdma_system_info.geo_system_index != 0xFFFF)
  397. blobmsg_add_u32(&status, "geo_system_index",
  398. res.data.additional_wcdma_system_info.geo_system_index);
  399. blobmsg_close_table(&status, c);
  400. }
  401. if (res.set.lte_service_status) {
  402. c = blobmsg_open_table(&status, "lte");
  403. print_system_info(res.data.lte_service_status.service_status,
  404. res.data.lte_service_status.true_service_status,
  405. res.data.lte_service_status.preferred_data_path,
  406. res.set.lte_system_info_v2,
  407. res.data.lte_system_info_v2.domain_valid,
  408. res.data.lte_system_info_v2.domain,
  409. res.data.lte_system_info_v2.service_capability_valid,
  410. res.data.lte_system_info_v2.service_capability,
  411. res.data.lte_system_info_v2.roaming_status_valid,
  412. res.data.lte_system_info_v2.roaming_status,
  413. res.data.lte_system_info_v2.forbidden_valid,
  414. res.data.lte_system_info_v2.forbidden,
  415. res.data.lte_system_info_v2.network_id_valid,
  416. res.data.lte_system_info_v2.mcc,
  417. res.data.lte_system_info_v2.mnc,
  418. res.data.lte_system_info_v2.lac_valid,
  419. res.data.lte_system_info_v2.lac);
  420. if (res.set.lte_system_info_v2 && res.data.lte_system_info_v2.tac_valid)
  421. blobmsg_add_u32(&status, "tracking_area_code",
  422. res.data.lte_system_info_v2.tac);
  423. if (res.set.lte_system_info_v2 && res.data.lte_system_info_v2.cid_valid) {
  424. blobmsg_add_u32(&status, "enodeb_id",res.data.lte_system_info_v2.cid/256);
  425. blobmsg_add_u32(&status, "cell_id",res.data.lte_system_info_v2.cid%256);
  426. }
  427. if (res.set.additional_lte_system_info &&
  428. res.data.additional_lte_system_info.geo_system_index != 0xFFFF)
  429. blobmsg_add_u32(&status, "geo_system_index",
  430. res.data.additional_lte_system_info.geo_system_index);
  431. if (res.set.lte_voice_support)
  432. blobmsg_add_u8(&status, "voice_support", res.data.lte_voice_support);
  433. if (res.set.ims_voice_support)
  434. blobmsg_add_u8(&status, "ims_voice_support", res.data.ims_voice_support);
  435. if (res.set.lte_cell_access_status)
  436. blobmsg_add_string(&status, "cell_access_status",
  437. cell_status[res.data.lte_cell_access_status]);
  438. if (res.set.network_selection_registration_restriction)
  439. blobmsg_add_u32(&status, "registration_restriction",
  440. res.data.network_selection_registration_restriction);
  441. if (res.set.lte_registration_domain)
  442. blobmsg_add_u32(&status, "registration_domain",
  443. res.data.lte_registration_domain);
  444. if (res.set.eutra_with_nr5g_availability)
  445. blobmsg_add_u8(&status, "5g_nsa_available",
  446. res.data.eutra_with_nr5g_availability);
  447. if (res.set.dcnr_restriction_info)
  448. blobmsg_add_u8(&status, "dcnr_restriction", res.data.dcnr_restriction_info);
  449. blobmsg_close_table(&status, c);
  450. }
  451. blobmsg_close_table(&status, t);
  452. }
  453. static enum qmi_cmd_result
  454. cmd_nas_get_system_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  455. {
  456. qmi_set_nas_get_system_info_request(msg);
  457. return QMI_CMD_REQUEST;
  458. }
  459. static void
  460. print_channel_info(int32_t cell_id, int32_t channel, uint32_t bw)
  461. {
  462. static const char *map_bandwidth[] = {
  463. [QMI_NAS_DL_BANDWIDTH_1_4] = "1.4",
  464. [QMI_NAS_DL_BANDWIDTH_3] = "3",
  465. [QMI_NAS_DL_BANDWIDTH_5] = "5",
  466. [QMI_NAS_DL_BANDWIDTH_10] = "10",
  467. [QMI_NAS_DL_BANDWIDTH_15] = "15",
  468. [QMI_NAS_DL_BANDWIDTH_20] = "20",
  469. [QMI_NAS_DL_BANDWIDTH_INVALID] = "invalid",
  470. [QMI_NAS_DL_BANDWIDTH_UNKNOWN] = "unknown",
  471. };
  472. blobmsg_add_u32(&status, "cell_id", cell_id);
  473. blobmsg_add_u32(&status, "channel", channel);
  474. print_earfcn_info(channel);
  475. blobmsg_add_string(&status, "bandwidth", map_bandwidth[bw]);
  476. }
  477. static void
  478. cmd_nas_get_lte_cphy_ca_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  479. {
  480. struct qmi_nas_get_lte_cphy_ca_info_response res;
  481. static const char *scell_state[] = {
  482. [QMI_NAS_SCELL_STATE_DECONFIGURED] = "deconfigured",
  483. [QMI_NAS_SCELL_STATE_DEACTIVATED] = "deactivated",
  484. [QMI_NAS_SCELL_STATE_ACTIVATED] = "activated",
  485. };
  486. char idx_buf[16];
  487. void *t, *c;
  488. int i;
  489. qmi_parse_nas_get_lte_cphy_ca_info_response(msg, &res);
  490. t = blobmsg_open_table(&status, NULL);
  491. if (res.set.phy_ca_agg_pcell_info) {
  492. c = blobmsg_open_table(&status, "primary");
  493. print_channel_info(res.data.phy_ca_agg_pcell_info.physical_cell_id,
  494. res.data.phy_ca_agg_pcell_info.rx_channel,
  495. res.data.phy_ca_agg_pcell_info.dl_bandwidth);
  496. blobmsg_close_table(&status, c);
  497. }
  498. if (res.set.phy_ca_agg_scell_info && res.data.phy_ca_agg_secondary_cells_n) {
  499. for (i = 0; i < res.data.phy_ca_agg_secondary_cells_n; i++) {
  500. if (res.data.phy_ca_agg_secondary_cells[i].rx_channel == 0)
  501. break;
  502. sprintf(idx_buf, "secondary_%d",
  503. res.data.phy_ca_agg_secondary_cells[i].cell_index);
  504. c = blobmsg_open_table(&status, idx_buf);
  505. print_channel_info(res.data.phy_ca_agg_secondary_cells[i].physical_cell_id,
  506. res.data.phy_ca_agg_secondary_cells[i].rx_channel,
  507. res.data.phy_ca_agg_secondary_cells[i].dl_bandwidth);
  508. blobmsg_add_string(&status, "state",
  509. scell_state[res.data.phy_ca_agg_secondary_cells[i].state]);
  510. blobmsg_close_table(&status, c);
  511. }
  512. } else {
  513. if (res.set.scell_index)
  514. sprintf(idx_buf, "secondary_%d", res.data.scell_index);
  515. else
  516. sprintf(idx_buf, "secondary");
  517. if (res.set.phy_ca_agg_scell_info && res.data.phy_ca_agg_scell_info.rx_channel != 0) {
  518. c = blobmsg_open_table(&status, idx_buf);
  519. print_channel_info(res.data.phy_ca_agg_scell_info.physical_cell_id,
  520. res.data.phy_ca_agg_scell_info.rx_channel,
  521. res.data.phy_ca_agg_scell_info.dl_bandwidth);
  522. blobmsg_add_string(&status, "state",
  523. scell_state[res.data.phy_ca_agg_scell_info.state]);
  524. blobmsg_close_table(&status, c);
  525. }
  526. }
  527. blobmsg_close_table(&status, t);
  528. }
  529. static enum qmi_cmd_result
  530. cmd_nas_get_lte_cphy_ca_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  531. {
  532. qmi_set_nas_get_lte_cphy_ca_info_request(msg);
  533. return QMI_CMD_REQUEST;
  534. }
  535. static void
  536. print_chain_info(int8_t radio, bool tuned, int32_t rssi, int32_t ecio, int32_t rsrp, int32_t rscp, uint32_t phase)
  537. {
  538. blobmsg_add_u8(&status, "tuned", tuned);
  539. blobmsg_add_double(&status, "rssi", (double) rssi*0.1);
  540. if (radio == QMI_NAS_RADIO_INTERFACE_LTE) {
  541. blobmsg_add_double(&status, "rsrq", (double) ecio*-0.1);
  542. blobmsg_add_double(&status, "rsrp", (double) rsrp*-0.1);
  543. }
  544. if (radio == QMI_NAS_RADIO_INTERFACE_UMTS) {
  545. blobmsg_add_double(&status, "ecio", (double) ecio*-0.1);
  546. blobmsg_add_double(&status, "rscp", (double) rscp*-0.1);
  547. }
  548. if (phase != 0xFFFFFFFF)
  549. blobmsg_add_double(&status, "phase", (double) phase*0.01);
  550. }
  551. static void
  552. cmd_nas_get_tx_rx_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  553. {
  554. struct qmi_nas_get_tx_rx_info_response res;
  555. void *c, *t;
  556. qmi_parse_nas_get_tx_rx_info_response(msg, &res);
  557. t = blobmsg_open_table(&status, NULL);
  558. if (res.set.rx_chain_0_info) {
  559. c = blobmsg_open_table(&status, "rx_chain_0");
  560. print_chain_info(tx_rx_req.data.radio_interface,
  561. res.data.rx_chain_0_info.is_radio_tuned,
  562. res.data.rx_chain_0_info.rx_power,
  563. res.data.rx_chain_0_info.ecio,
  564. res.data.rx_chain_0_info.rsrp,
  565. res.data.rx_chain_0_info.rscp,
  566. res.data.rx_chain_0_info.phase);
  567. blobmsg_close_table(&status, c);
  568. }
  569. if (res.set.rx_chain_1_info) {
  570. c = blobmsg_open_table(&status, "rx_chain_1");
  571. print_chain_info(tx_rx_req.data.radio_interface,
  572. res.data.rx_chain_1_info.is_radio_tuned,
  573. res.data.rx_chain_1_info.rx_power,
  574. res.data.rx_chain_1_info.ecio,
  575. res.data.rx_chain_1_info.rsrp,
  576. res.data.rx_chain_1_info.rscp,
  577. res.data.rx_chain_1_info.phase);
  578. blobmsg_close_table(&status, c);
  579. }
  580. if (res.set.rx_chain_2_info) {
  581. c = blobmsg_open_table(&status, "rx_chain_2");
  582. print_chain_info(tx_rx_req.data.radio_interface,
  583. res.data.rx_chain_2_info.is_radio_tuned,
  584. res.data.rx_chain_2_info.rx_power,
  585. res.data.rx_chain_2_info.ecio,
  586. res.data.rx_chain_2_info.rsrp,
  587. res.data.rx_chain_2_info.rscp,
  588. res.data.rx_chain_2_info.phase);
  589. blobmsg_close_table(&status, c);
  590. }
  591. if (res.set.rx_chain_3_info) {
  592. c = blobmsg_open_table(&status, "rx_chain_3");
  593. print_chain_info(tx_rx_req.data.radio_interface,
  594. res.data.rx_chain_3_info.is_radio_tuned,
  595. res.data.rx_chain_3_info.rx_power,
  596. res.data.rx_chain_3_info.ecio,
  597. res.data.rx_chain_3_info.rsrp,
  598. res.data.rx_chain_3_info.rscp,
  599. res.data.rx_chain_3_info.phase);
  600. blobmsg_close_table(&status, c);
  601. }
  602. if (res.set.tx_info) {
  603. c = blobmsg_open_table(&status, "tx");
  604. blobmsg_add_u8(&status, "traffic", res.data.tx_info.is_in_traffic);
  605. if (res.data.tx_info.is_in_traffic)
  606. blobmsg_add_double(&status, "tx_power",
  607. (double) res.data.tx_info.tx_power*0.1);
  608. blobmsg_close_table(&status, c);
  609. }
  610. blobmsg_close_table(&status, t);
  611. }
  612. static enum qmi_cmd_result
  613. cmd_nas_get_tx_rx_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  614. {
  615. int radio = 0;
  616. if (!strcmp(arg, "lte"))
  617. radio = QMI_NAS_RADIO_INTERFACE_LTE;
  618. else if (!strcmp(arg, "umts"))
  619. radio = QMI_NAS_RADIO_INTERFACE_UMTS;
  620. else if (!strcmp(arg, "gsm"))
  621. radio = QMI_NAS_RADIO_INTERFACE_GSM;
  622. else
  623. return uqmi_add_error("Invalid argument");
  624. qmi_set(&tx_rx_req, radio_interface, radio);
  625. qmi_set_nas_get_tx_rx_info_request(msg, &tx_rx_req);
  626. return QMI_CMD_REQUEST;
  627. }
  628. static void
  629. print_lte_info(int32_t cell_id, int16_t rsrp, int16_t rsrq, int16_t rssi)
  630. {
  631. blobmsg_add_u32(&status, "physical_cell_id", cell_id);
  632. blobmsg_add_double(&status, "rsrq", ((double)rsrq)/10);
  633. blobmsg_add_double(&status, "rsrp", ((double)rsrp)/10);
  634. blobmsg_add_double(&status, "rssi", ((double)rssi)/10);
  635. }
  636. static void
  637. print_sel_info(int32_t priority, int32_t high, int32_t low)
  638. {
  639. blobmsg_add_u32(&status, "cell_reselection_priority", priority);
  640. blobmsg_add_u32(&status, "cell_reselection_low", low);
  641. blobmsg_add_u32(&status, "cell_reselection_high", high);
  642. }
  643. static void
  644. cmd_nas_get_cell_location_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  645. {
  646. struct qmi_nas_get_cell_location_info_response res;
  647. void *c, *t, *cell, *freq;
  648. int i, j;
  649. qmi_parse_nas_get_cell_location_info_response(msg, &res);
  650. t = blobmsg_open_table(&status, NULL);
  651. if (res.set.umts_info_v2) {
  652. c = blobmsg_open_table(&status, "umts_info");
  653. blobmsg_add_u32(&status, "location_area_code", res.data.umts_info_v2.lac);
  654. blobmsg_add_u32(&status, "cell_id", res.data.umts_info_v2.cell_id);
  655. blobmsg_add_u32(&status, "channel",
  656. res.data.umts_info_v2.utra_absolute_rf_channel_number);
  657. blobmsg_add_u32(&status, "primary_scrambling_code",
  658. res.data.umts_info_v2.primary_scrambling_code);
  659. blobmsg_add_u32(&status, "rscp", res.data.umts_info_v2.rscp);
  660. blobmsg_add_u32(&status, "ecio", res.data.umts_info_v2.ecio);
  661. for (j = 0; j < res.data.umts_info_v2.cell_n; j++) {
  662. cell = blobmsg_open_table(&status, NULL);
  663. blobmsg_add_u32(&status, "channel",
  664. res.data.umts_info_v2.cell[j].utra_absolute_rf_channel_number);
  665. blobmsg_add_u32(&status, "primary_scrambling_code",
  666. res.data.umts_info_v2.cell[j].primary_scrambling_code);
  667. blobmsg_add_u32(&status, "rscp", res.data.umts_info_v2.cell[j].rscp);
  668. blobmsg_add_u32(&status, "ecio", res.data.umts_info_v2.cell[j].ecio);
  669. blobmsg_close_table(&status, cell);
  670. }
  671. for (j = 0; j < res.data.umts_info_v2.neighboring_geran_n; j++) {
  672. cell = blobmsg_open_table(&status, "neighboring_geran");
  673. blobmsg_add_u32(&status, "channel",
  674. res.data.umts_info_v2.neighboring_geran[j].geran_absolute_rf_channel_number);
  675. blobmsg_add_u8(&status, "network_color_code",
  676. res.data.umts_info_v2.neighboring_geran[j].network_color_code);
  677. blobmsg_add_u8(&status, "base_station_color_code",
  678. res.data.umts_info_v2.neighboring_geran[j].base_station_color_code);
  679. blobmsg_add_u32(&status, "rssi",
  680. res.data.umts_info_v2.neighboring_geran[j].rssi);
  681. blobmsg_close_table(&status, cell);
  682. }
  683. blobmsg_close_table(&status, c);
  684. }
  685. if (res.set.intrafrequency_lte_info_v2) {
  686. c = blobmsg_open_table(&status, "intrafrequency_lte_info");
  687. blobmsg_add_u32(&status, "tracking_area_code",
  688. res.data.intrafrequency_lte_info_v2.tracking_area_code);
  689. blobmsg_add_u32(&status, "enodeb_id",
  690. res.data.intrafrequency_lte_info_v2.global_cell_id/256);
  691. blobmsg_add_u32(&status, "cell_id",
  692. res.data.intrafrequency_lte_info_v2.global_cell_id%256);
  693. blobmsg_add_u32(&status, "channel",
  694. res.data.intrafrequency_lte_info_v2.eutra_absolute_rf_channel_number);
  695. print_earfcn_info(res.data.intrafrequency_lte_info_v2.eutra_absolute_rf_channel_number);
  696. blobmsg_add_u32(&status, "serving_cell_id",
  697. res.data.intrafrequency_lte_info_v2.serving_cell_id);
  698. if (res.data.intrafrequency_lte_info_v2.ue_in_idle) {
  699. blobmsg_add_u32(&status, "cell_reselection_priority",
  700. res.data.intrafrequency_lte_info_v2.cell_reselection_priority);
  701. blobmsg_add_u32(&status, "s_non_intra_search_threshold",
  702. res.data.intrafrequency_lte_info_v2.s_non_intra_search_threshold);
  703. blobmsg_add_u32(&status, "serving_cell_low_threshold",
  704. res.data.intrafrequency_lte_info_v2.serving_cell_low_threshold);
  705. blobmsg_add_u32(&status, "s_intra_search_threshold",
  706. res.data.intrafrequency_lte_info_v2.s_intra_search_threshold);
  707. }
  708. for (i = 0; i < res.data.intrafrequency_lte_info_v2.cell_n; i++) {
  709. cell = blobmsg_open_table(&status, NULL);
  710. print_lte_info(res.data.intrafrequency_lte_info_v2.cell[i].physical_cell_id,
  711. res.data.intrafrequency_lte_info_v2.cell[i].rsrq,
  712. res.data.intrafrequency_lte_info_v2.cell[i].rsrp,
  713. res.data.intrafrequency_lte_info_v2.cell[i].rssi);
  714. if (res.data.intrafrequency_lte_info_v2.ue_in_idle)
  715. blobmsg_add_u32(&status, "cell_selection_rx_level",
  716. res.data.intrafrequency_lte_info_v2.cell[i].cell_selection_rx_level);
  717. blobmsg_close_table(&status, cell);
  718. }
  719. blobmsg_close_table(&status, c);
  720. }
  721. if (res.set.interfrequency_lte_info) {
  722. if (res.data.interfrequency_lte_info.frequency_n > 0)
  723. c = blobmsg_open_table(&status, "interfrequency_lte_info");
  724. for (i = 0; i < res.data.interfrequency_lte_info.frequency_n; i++) {
  725. freq = blobmsg_open_table(&status, NULL);
  726. blobmsg_add_u32(&status, "channel",
  727. res.data.interfrequency_lte_info.frequency[i].eutra_absolute_rf_channel_number);
  728. print_earfcn_info(res.data.interfrequency_lte_info.frequency[i].eutra_absolute_rf_channel_number);
  729. if (res.data.interfrequency_lte_info.ue_in_idle) {
  730. print_sel_info(res.data.interfrequency_lte_info.frequency[i].cell_reselection_priority,
  731. res.data.interfrequency_lte_info.frequency[i].cell_selection_rx_level_high_threshold,
  732. res.data.interfrequency_lte_info.frequency[i].cell_selection_rx_level_low_threshold);
  733. }
  734. for (j = 0; j < res.data.interfrequency_lte_info.frequency[i].cell_n; j++) {
  735. cell = blobmsg_open_table(&status, NULL);
  736. print_lte_info(res.data.interfrequency_lte_info.frequency[i].cell[j].physical_cell_id,
  737. res.data.interfrequency_lte_info.frequency[i].cell[j].rsrq,
  738. res.data.interfrequency_lte_info.frequency[i].cell[j].rsrp,
  739. res.data.interfrequency_lte_info.frequency[i].cell[j].rssi);
  740. if (res.data.interfrequency_lte_info.ue_in_idle)
  741. blobmsg_add_u32(&status, "cell_selection_rx_level",
  742. res.data.interfrequency_lte_info.frequency[i].cell[j].cell_selection_rx_level);
  743. blobmsg_close_table(&status, cell);
  744. }
  745. blobmsg_close_table(&status, freq);
  746. }
  747. if (res.data.interfrequency_lte_info.frequency_n > 0)
  748. blobmsg_close_table(&status, c);
  749. }
  750. if (res.set.lte_info_neighboring_gsm) {
  751. if (res.data.lte_info_neighboring_gsm.frequency_n > 0)
  752. c = blobmsg_open_table(&status, "lte_info_neighboring_gsm");
  753. for (i = 0; i < res.data.lte_info_neighboring_gsm.frequency_n; i++) {
  754. freq = blobmsg_open_table(&status, NULL);
  755. blobmsg_add_u32(&status, "ncc_permitted",
  756. res.data.lte_info_neighboring_gsm.frequency[i].ncc_permitted);
  757. if (res.data.lte_info_neighboring_gsm.ue_in_idle) {
  758. print_sel_info(res.data.lte_info_neighboring_gsm.frequency[i].cell_reselection_priority,
  759. res.data.lte_info_neighboring_gsm.frequency[i].cell_reselection_high_threshold,
  760. res.data.lte_info_neighboring_gsm.frequency[i].cell_reselection_low_threshold);
  761. }
  762. for (j = 0; j < res.data.lte_info_neighboring_gsm.frequency[i].cell_n; j++) {
  763. cell = blobmsg_open_table(&status, NULL);
  764. blobmsg_add_u32(&status, "channel",
  765. res.data.lte_info_neighboring_gsm.frequency[i].cell[j].geran_absolute_rf_channel_number);
  766. blobmsg_add_u32(&status, "base_station_identity_code",
  767. res.data.lte_info_neighboring_gsm.frequency[i].cell[j].base_station_identity_code);
  768. blobmsg_add_double(&status, "rssi",
  769. ((double)res.data.lte_info_neighboring_gsm.frequency[i].cell[j].rssi)/10);
  770. if (res.data.lte_info_neighboring_gsm.ue_in_idle)
  771. blobmsg_add_u32(&status, "cell_selection_rx_level",
  772. res.data.lte_info_neighboring_gsm.frequency[i].cell[j].cell_selection_rx_level);
  773. blobmsg_close_table(&status, cell);
  774. }
  775. blobmsg_close_table(&status, freq);
  776. }
  777. if (res.data.lte_info_neighboring_gsm.frequency_n > 0)
  778. blobmsg_close_table(&status, c);
  779. }
  780. if (res.set.lte_info_neighboring_wcdma) {
  781. if (res.data.lte_info_neighboring_wcdma.frequency_n > 0)
  782. c = blobmsg_open_table(&status, "lte_info_neighboring_wcdma");
  783. for (i = 0; i < res.data.lte_info_neighboring_wcdma.frequency_n; i++) {
  784. freq = blobmsg_open_table(&status, NULL);
  785. blobmsg_add_u32(&status, "channel",
  786. res.data.lte_info_neighboring_wcdma.frequency[i].utra_absolute_rf_channel_number);
  787. if (res.data.lte_info_neighboring_wcdma.ue_in_idle) {
  788. print_sel_info(res.data.lte_info_neighboring_wcdma.frequency[i].cell_reselection_priority,
  789. res.data.lte_info_neighboring_wcdma.frequency[i].cell_reselection_high_threshold,
  790. res.data.lte_info_neighboring_wcdma.frequency[i].cell_reselection_low_threshold);
  791. }
  792. for (j = 0; j < res.data.lte_info_neighboring_wcdma.frequency[i].cell_n; j++) {
  793. cell = blobmsg_open_table(&status, NULL);
  794. blobmsg_add_u32(&status, "primary_scrambling_code",
  795. res.data.lte_info_neighboring_wcdma.frequency[i].cell[j].primary_scrambling_code);
  796. blobmsg_add_double(&status, "rscp",
  797. ((double)res.data.lte_info_neighboring_wcdma.frequency[i].cell[j].cpich_rscp)/10);
  798. blobmsg_add_double(&status, "ecno",
  799. ((double)res.data.lte_info_neighboring_wcdma.frequency[i].cell[j].cpich_ecno)/10);
  800. if (res.data.lte_info_neighboring_wcdma.ue_in_idle)
  801. blobmsg_add_u32(&status, "cell_selection_rx_level",
  802. res.data.lte_info_neighboring_wcdma.frequency[i].cell[j].cell_selection_rx_level);
  803. blobmsg_close_table(&status, cell);
  804. }
  805. blobmsg_close_table(&status, freq);
  806. }
  807. if (res.data.lte_info_neighboring_wcdma.frequency_n > 0)
  808. blobmsg_close_table(&status, c);
  809. }
  810. if (res.set.umts_info_neighboring_lte) {
  811. if (res.data.umts_info_neighboring_lte.frequency_n > 0)
  812. c = blobmsg_open_table(&status, "umts_info_neighboring_lte");
  813. for (i = 0; i < res.data.umts_info_neighboring_lte.frequency_n; i++) {
  814. freq = blobmsg_open_table(&status, NULL);
  815. blobmsg_add_u32(&status, "channel",
  816. res.data.umts_info_neighboring_lte.frequency[i].eutra_absolute_rf_channel_number);
  817. print_earfcn_info(res.data.umts_info_neighboring_lte.frequency[i].eutra_absolute_rf_channel_number);
  818. blobmsg_add_u32(&status, "physical_cell_id",
  819. res.data.umts_info_neighboring_lte.frequency[i].physical_cell_id);
  820. blobmsg_add_double(&status, "rsrp",
  821. (double) res.data.umts_info_neighboring_lte.frequency[i].rsrp);
  822. blobmsg_add_double(&status, "rsrq",
  823. (double) res.data.umts_info_neighboring_lte.frequency[i].rsrq);
  824. blobmsg_add_u32(&status, "cell_selection_rx_level",
  825. res.data.umts_info_neighboring_lte.frequency[i].cell_selection_rx_level);
  826. blobmsg_close_table(&status, freq);
  827. }
  828. if (res.data.umts_info_neighboring_lte.frequency_n > 0)
  829. blobmsg_close_table(&status, c);
  830. }
  831. blobmsg_close_table(&status, t);
  832. }
  833. static enum qmi_cmd_result
  834. cmd_nas_get_cell_location_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  835. {
  836. qmi_set_nas_get_cell_location_info_request(msg);
  837. return QMI_CMD_REQUEST;
  838. }
  839. static enum qmi_cmd_result
  840. cmd_nas_get_signal_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  841. {
  842. qmi_set_nas_get_signal_info_request(msg);
  843. return QMI_CMD_REQUEST;
  844. }
  845. static void
  846. cmd_nas_get_serving_system_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  847. {
  848. struct qmi_nas_get_serving_system_response res;
  849. static const char *reg_states[] = {
  850. [QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED] = "not_registered",
  851. [QMI_NAS_REGISTRATION_STATE_REGISTERED] = "registered",
  852. [QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED_SEARCHING] = "searching",
  853. [QMI_NAS_REGISTRATION_STATE_REGISTRATION_DENIED] = "registering_denied",
  854. [QMI_NAS_REGISTRATION_STATE_UNKNOWN] = "unknown",
  855. };
  856. void *c;
  857. qmi_parse_nas_get_serving_system_response(msg, &res);
  858. c = blobmsg_open_table(&status, NULL);
  859. if (res.set.serving_system) {
  860. int state = res.data.serving_system.registration_state;
  861. if (state > QMI_NAS_REGISTRATION_STATE_UNKNOWN)
  862. state = QMI_NAS_REGISTRATION_STATE_UNKNOWN;
  863. blobmsg_add_string(&status, "registration", reg_states[state]);
  864. }
  865. if (res.set.current_plmn) {
  866. blobmsg_add_u32(&status, "plmn_mcc", res.data.current_plmn.mcc);
  867. blobmsg_add_u32(&status, "plmn_mnc", res.data.current_plmn.mnc);
  868. if (res.data.current_plmn.description)
  869. blobmsg_add_string(&status, "plmn_description", res.data.current_plmn.description);
  870. }
  871. if (res.set.roaming_indicator)
  872. blobmsg_add_u8(&status, "roaming", !res.data.roaming_indicator);
  873. blobmsg_close_table(&status, c);
  874. }
  875. static enum qmi_cmd_result
  876. cmd_nas_get_serving_system_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  877. {
  878. qmi_set_nas_get_serving_system_request(msg);
  879. return QMI_CMD_REQUEST;
  880. }
  881. static void
  882. cmd_nas_get_plmn_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  883. {
  884. struct qmi_nas_get_system_selection_preference_response res;
  885. static const char *modes[] = {
  886. [QMI_NAS_NETWORK_SELECTION_PREFERENCE_AUTOMATIC] = "automatic",
  887. [QMI_NAS_NETWORK_SELECTION_PREFERENCE_MANUAL] = "manual",
  888. };
  889. void *c;
  890. qmi_parse_nas_get_system_selection_preference_response(msg, &res);
  891. c = blobmsg_open_table(&status, NULL);
  892. if (res.set.network_selection_preference) {
  893. blobmsg_add_string(&status, "mode", modes[res.data.network_selection_preference]);
  894. }
  895. if (res.set.manual_network_selection) {
  896. blobmsg_add_u32(&status, "mcc", res.data.manual_network_selection.mcc);
  897. blobmsg_add_u32(&status, "mnc", res.data.manual_network_selection.mnc);
  898. }
  899. blobmsg_close_table(&status, c);
  900. }
  901. static enum qmi_cmd_result
  902. cmd_nas_get_plmn_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  903. {
  904. qmi_set_nas_get_system_selection_preference_request(msg);
  905. return QMI_CMD_REQUEST;
  906. }
  907. static void
  908. cmd_nas_network_scan_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
  909. {
  910. static struct qmi_nas_network_scan_response res;
  911. const char *network_status[] = {
  912. "current_serving",
  913. "available",
  914. "home",
  915. "roaming",
  916. "forbidden",
  917. "not_forbidden",
  918. "preferred",
  919. "not_preferred",
  920. };
  921. const char *radio[] = {
  922. [QMI_NAS_RADIO_INTERFACE_NONE] = "none",
  923. [QMI_NAS_RADIO_INTERFACE_CDMA_1X] = "cdma-1x",
  924. [QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO] = "cdma-1x_evdo",
  925. [QMI_NAS_RADIO_INTERFACE_AMPS] = "amps",
  926. [QMI_NAS_RADIO_INTERFACE_GSM] = "gsm",
  927. [QMI_NAS_RADIO_INTERFACE_UMTS] = "umts",
  928. [QMI_NAS_RADIO_INTERFACE_LTE] = "lte",
  929. [QMI_NAS_RADIO_INTERFACE_TD_SCDMA] = "td-scdma",
  930. };
  931. void *t, *c, *info, *stat;
  932. int i, j;
  933. qmi_parse_nas_network_scan_response(msg, &res);
  934. t = blobmsg_open_table(&status, NULL);
  935. c = blobmsg_open_array(&status, "network_info");
  936. for (i = 0; i < res.data.network_information_n; i++) {
  937. info = blobmsg_open_table(&status, NULL);
  938. blobmsg_add_u32(&status, "mcc", res.data.network_information[i].mcc);
  939. blobmsg_add_u32(&status, "mnc", res.data.network_information[i].mnc);
  940. if (res.data.network_information[i].description)
  941. blobmsg_add_string(&status, "description", res.data.network_information[i].description);
  942. stat = blobmsg_open_array(&status, "status");
  943. for (j = 0; j < ARRAY_SIZE(network_status); j++) {
  944. if (!(res.data.network_information[i].network_status & (1 << j)))
  945. continue;
  946. blobmsg_add_string(&status, NULL, network_status[j]);
  947. }
  948. blobmsg_close_array(&status, stat);
  949. blobmsg_close_table(&status, info);
  950. }
  951. blobmsg_close_array(&status, c);
  952. c = blobmsg_open_array(&status, "radio_access_technology");
  953. for (i = 0; i < res.data.radio_access_technology_n; i++) {
  954. const char *r = "unknown";
  955. int r_i = res.data.radio_access_technology[i].radio_interface;
  956. info = blobmsg_open_table(&status, NULL);
  957. blobmsg_add_u32(&status, "mcc", res.data.radio_access_technology[i].mcc);
  958. blobmsg_add_u32(&status, "mnc", res.data.radio_access_technology[i].mnc);
  959. if (r_i >= 0 && r_i < ARRAY_SIZE(radio))
  960. r = radio[r_i];
  961. blobmsg_add_string(&status, "radio", r);
  962. blobmsg_close_table(&status, info);
  963. }
  964. blobmsg_close_array(&status, c);
  965. blobmsg_close_table(&status, t);
  966. }
  967. static enum qmi_cmd_result
  968. cmd_nas_network_scan_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
  969. {
  970. struct qmi_nas_network_scan_request sreq = {
  971. QMI_INIT(network_type,
  972. QMI_NAS_NETWORK_SCAN_TYPE_GSM |
  973. QMI_NAS_NETWORK_SCAN_TYPE_UMTS |
  974. QMI_NAS_NETWORK_SCAN_TYPE_LTE |
  975. QMI_NAS_NETWORK_SCAN_TYPE_TD_SCDMA),
  976. };
  977. qmi_set_nas_network_scan_request(msg, &sreq);
  978. return QMI_CMD_REQUEST;
  979. }