nw_demo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*============================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =============================================================================*/
  5. /*===========================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ---------- ------------ ----------------------------------------------------
  11. =============================================================================*/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "ql_app_feature_config.h"
  16. #include "ql_api_osi.h"
  17. #include "ql_log.h"
  18. #include "ql_api_nw.h"
  19. #define QL_NW_LOG_LEVEL QL_LOG_LEVEL_INFO
  20. #define QL_NW_DEMO_LOG(msg, ...) QL_LOG(QL_NW_LOG_LEVEL, "ql_nw_demo", msg, ##__VA_ARGS__)
  21. ql_task_t nw_task = NULL;
  22. static void ql_nw_cause_print(ql_nw_cause_s *cause_info)
  23. {
  24. struct
  25. {
  26. ql_nw_cause_type_e type;
  27. char *str;
  28. }cause[]=
  29. {
  30. {QUEC_NW_CS_INTERNAL_CAUSE ,"No Cause"},
  31. {QUEC_NW_CS_NETWORK_REJECT ,"GMM Cause "},
  32. {QUEC_NW_PS_LTE_CAUSE ,"ESM Cause "},
  33. {QUEC_NW_PS_LTE_LOCAL_CAUSE ,"EMM Cause "},
  34. {QUEC_NW_PS_GPRS_CAUSE ,"SM Cause "},
  35. };
  36. uint8 size = sizeof(cause)/sizeof(cause[0]);
  37. for(int i = 0 ; i < size; i++)
  38. {
  39. if(cause_info->causeId == cause[i].type)
  40. {
  41. QL_NW_DEMO_LOG("%s#%d",cause[i].str,cause_info->causeDetail);
  42. break;
  43. }
  44. }
  45. }
  46. void ql_nw_notify_cb(uint8_t sim_id, unsigned int ind_type, void *ind_msg_buf)
  47. {
  48. switch(ind_type)
  49. {
  50. case QUEC_NW_VOICE_REG_STATUS_IND:
  51. {
  52. ql_nw_common_reg_status_info_s *voice_reg_status=(ql_nw_common_reg_status_info_s *)ind_msg_buf;
  53. QL_NW_DEMO_LOG("Sim%d voice: state:%d; lac:0x%X; cid:0x%X; act:%d; ue_stat:%d",
  54. sim_id,
  55. voice_reg_status->state,
  56. voice_reg_status->lac,
  57. voice_reg_status->cid,
  58. voice_reg_status->act,
  59. voice_reg_status->ue_state);
  60. break;
  61. }
  62. case QUEC_NW_DATA_REG_STATUS_IND:
  63. {
  64. ql_nw_common_reg_status_info_s *data_reg_status=(ql_nw_common_reg_status_info_s *)ind_msg_buf;
  65. QL_NW_DEMO_LOG("Sim%d data: state:%d; lac:0x%X; cid:0x%X; act:%d; ue_stat:%d",
  66. sim_id,
  67. data_reg_status->state,
  68. data_reg_status->lac,
  69. data_reg_status->cid,
  70. data_reg_status->act,
  71. data_reg_status->ue_state);
  72. break;
  73. }
  74. #if 0 //If you care about the changes of signal quality, you can change "#if 0" to "#if 1"
  75. case QUEC_NW_SIGNAL_QUALITY_IND:
  76. {
  77. ql_nw_signal_strength_info_s *signal_info=(ql_nw_signal_strength_info_s *)ind_msg_buf;
  78. QL_NW_DEMO_LOG("Sim%d signal: rssi:%d, bitErrorRate:%d, rsrp:%d, rsrq:%d",
  79. sim_id,
  80. signal_info->rssi, signal_info->bitErrorRate,
  81. signal_info->rsrp, signal_info->rsrq);
  82. break;
  83. }
  84. #endif
  85. case QUEC_NW_NITZ_TIME_UPDATE_IND:
  86. {
  87. ql_nw_nitz_time_info_s *nitz_info=(ql_nw_nitz_time_info_s *)ind_msg_buf;
  88. QL_NW_DEMO_LOG("nitz update: nitz_time:%s, abs_time:%ld", nitz_info->nitz_time, nitz_info->abs_time);
  89. break;
  90. }
  91. case QUEC_NW_CAUSE_IND:
  92. {
  93. ql_nw_cause_s *cause_info=(ql_nw_cause_s *)ind_msg_buf;
  94. QL_NW_DEMO_LOG("cause info: causeId:%d, causeDetail:%d", cause_info->causeId, cause_info->causeDetail);
  95. ql_nw_cause_print(cause_info);
  96. break;
  97. }
  98. #ifdef QL_APP_FEATURE_JAMDET
  99. case QUEC_NW_JAMMING_DETECT_IND:
  100. {
  101. uint8_t *jamming_status=(uint8_t *)ind_msg_buf;
  102. QL_NW_DEMO_LOG("jamming detect status:%d", *jamming_status);
  103. break;
  104. }
  105. #endif
  106. case QUEC_NW_CELL_INFO_IND:
  107. {
  108. ql_nw_cell_info_s *cell_info = NULL;
  109. cell_info = (ql_nw_cell_info_s *)calloc(1,sizeof(ql_nw_cell_info_s));
  110. memcpy(cell_info,(ql_nw_cell_info_s *)ind_msg_buf,sizeof(ql_nw_cell_info_s));
  111. if(cell_info->gsm_info_valid)
  112. {
  113. for(int cell_index = 0; cell_index < cell_info->gsm_info_num; cell_index++)
  114. {
  115. QL_NW_DEMO_LOG("Cell_%d [GSM] flag:%d, cid:0x%X, mcc:%d, mnc:%02d, lac:0x%X, arfcn:%d, bsic:%d, rssi:%d",
  116. cell_index,
  117. cell_info->gsm_info[cell_index].flag,
  118. cell_info->gsm_info[cell_index].cid,
  119. cell_info->gsm_info[cell_index].mcc,
  120. cell_info->gsm_info[cell_index].mnc,
  121. cell_info->gsm_info[cell_index].lac,
  122. cell_info->gsm_info[cell_index].arfcn,
  123. cell_info->gsm_info[cell_index].bsic,
  124. cell_info->gsm_info[cell_index].rssi);
  125. }
  126. }
  127. if(cell_info->lte_info_valid)
  128. {
  129. for(int cell_index = 0; cell_index < cell_info->lte_info_num; cell_index++)
  130. {
  131. QL_NW_DEMO_LOG("Cell_%d [LTE] flag:%d, cid:0x%X, mcc:%d, mnc:%02d, tac:0x%X, pci:%d, earfcn:%d, rssi:%d",
  132. cell_index,
  133. cell_info->lte_info[cell_index].flag,
  134. cell_info->lte_info[cell_index].cid,
  135. cell_info->lte_info[cell_index].mcc,
  136. cell_info->lte_info[cell_index].mnc,
  137. cell_info->lte_info[cell_index].tac,
  138. cell_info->lte_info[cell_index].pci,
  139. cell_info->lte_info[cell_index].earfcn,
  140. cell_info->lte_info[cell_index].rssi);
  141. }
  142. }
  143. free(cell_info);
  144. cell_info = NULL;
  145. break;
  146. }
  147. }
  148. }
  149. static void nw_app_thread(void * arg)
  150. {
  151. QlOSStatus err = 0;
  152. int ret = 0;
  153. uint8_t sim_id = 0;
  154. unsigned char cell_index = 0, csq = 0;
  155. ql_nw_mode_type_e nw_mode = 0;
  156. ql_nw_reg_status_info_s *reg_info = (ql_nw_reg_status_info_s *)calloc(1, sizeof(ql_nw_reg_status_info_s));
  157. ql_nw_signal_strength_info_s *signal_info = (ql_nw_signal_strength_info_s *)calloc(1, sizeof(ql_nw_signal_strength_info_s));
  158. ql_nw_operator_info_s *oper_info = (ql_nw_operator_info_s *)calloc(1, sizeof(ql_nw_operator_info_s));
  159. ql_nw_seclection_info_s *select_info = (ql_nw_seclection_info_s *)calloc(1, sizeof(ql_nw_seclection_info_s));
  160. ql_nw_nitz_time_info_s *nitz_info = (ql_nw_nitz_time_info_s *)calloc(1, sizeof(ql_nw_nitz_time_info_s));
  161. ql_nw_cell_info_s *cell_info = (ql_nw_cell_info_s *)calloc(1, sizeof(ql_nw_cell_info_s));
  162. ql_nw_cause_s cause = {0};
  163. if((NULL == reg_info) || (NULL == signal_info) || (NULL == oper_info)
  164. || (NULL == select_info) || (NULL == nitz_info) || (NULL == cell_info))
  165. {
  166. QL_NW_DEMO_LOG("calloc fail");
  167. goto exit;
  168. }
  169. if(ql_nw_register_cb(ql_nw_notify_cb) != QL_NW_SUCCESS)
  170. {
  171. QL_NW_DEMO_LOG("register network callback fail");
  172. goto exit;
  173. }
  174. #ifdef QL_APP_FEATURE_JAMDET
  175. ql_nw_jamdet_state_e jamdet_status = QL_NO_JAMMING;
  176. ret = ql_nw_set_jamdet_mode(sim_id, true);
  177. QL_NW_DEMO_LOG("ret=0x%x", ret);
  178. #endif
  179. ret = ql_nw_get_cell_info_async(sim_id);
  180. QL_NW_DEMO_LOG("get cell info,ret=0x%x", ret);
  181. while(1)
  182. {
  183. ql_rtos_task_sleep_ms(10000);
  184. QL_NW_DEMO_LOG("====================nw demo start===================");
  185. ret = ql_nw_get_mode(sim_id, &nw_mode);
  186. QL_NW_DEMO_LOG("ret=0x%x, nw_mode:%d", ret, nw_mode);
  187. ret = ql_nw_get_reg_status(sim_id, reg_info);
  188. QL_NW_DEMO_LOG("ret=0x%x", ret);
  189. QL_NW_DEMO_LOG("voice: state:%d, lac:0x%X, cid:0x%X, act:%d, ue_stat:%d",
  190. reg_info->voice_reg.state, reg_info->voice_reg.lac, reg_info->voice_reg.cid, reg_info->voice_reg.act, reg_info->voice_reg.ue_state);
  191. QL_NW_DEMO_LOG("data: state:%d, lac:0x%X, cid:0x%X, act:%d, ue_stat:%d",
  192. reg_info->data_reg.state, reg_info->data_reg.lac, reg_info->data_reg.cid, reg_info->data_reg.act, reg_info->data_reg.ue_state);
  193. ret = ql_nw_get_csq(sim_id, &csq);
  194. QL_NW_DEMO_LOG("ret=0x%x, csq:%d", ret, csq);
  195. ret = ql_nw_get_signal_strength(sim_id, signal_info);
  196. QL_NW_DEMO_LOG("ret=0x%x, rssi:%d, bitErrorRate:%d, rsrp:%d, rsrq:%d",
  197. ret, signal_info->rssi, signal_info->bitErrorRate,
  198. signal_info->rsrp, signal_info->rsrq);
  199. ret = ql_nw_get_operator_name(sim_id, oper_info);
  200. QL_NW_DEMO_LOG("ret=0x%x, long_oper_name:%s, short_oper_name:%s, mcc:%s, mnc:%s",
  201. ret, oper_info->long_oper_name, oper_info->short_oper_name, oper_info->mcc, oper_info->mnc);
  202. ret = ql_nw_get_selection(sim_id, select_info);
  203. QL_NW_DEMO_LOG("ret=0x%x, nw_selection_mode:%d, mcc:%s, mnc:%s, act:%d",
  204. ret, select_info->nw_selection_mode, select_info->mcc, select_info->mnc, select_info->act);
  205. ret = ql_nw_get_nitz_time_info(nitz_info);
  206. QL_NW_DEMO_LOG("ret=0x%x, nitz_time:%s, abs_time:%ld", ret, nitz_info->nitz_time, nitz_info->abs_time);
  207. ret = ql_nw_get_cell_info(sim_id, cell_info);
  208. QL_NW_DEMO_LOG("ret=0x%x", ret);
  209. if(cell_info->gsm_info_valid)
  210. {
  211. for(cell_index = 0; cell_index < cell_info->gsm_info_num; cell_index++)
  212. {
  213. QL_NW_DEMO_LOG("Cell_%d [GSM] flag:%d, cid:0x%X, mcc:%d, mnc:%02d, lac:0x%X, arfcn:%d, bsic:%d, rssi:%d",
  214. cell_index,
  215. cell_info->gsm_info[cell_index].flag,
  216. cell_info->gsm_info[cell_index].cid,
  217. cell_info->gsm_info[cell_index].mcc,
  218. cell_info->gsm_info[cell_index].mnc,
  219. cell_info->gsm_info[cell_index].lac,
  220. cell_info->gsm_info[cell_index].arfcn,
  221. cell_info->gsm_info[cell_index].bsic,
  222. cell_info->gsm_info[cell_index].rssi);
  223. }
  224. }
  225. if(cell_info->lte_info_valid)
  226. {
  227. for(cell_index = 0; cell_index < cell_info->lte_info_num; cell_index++)
  228. {
  229. QL_NW_DEMO_LOG("Cell_%d [LTE] flag:%d, cid:0x%X, mcc:%d, mnc:%02d, tac:0x%X, pci:%d, earfcn:%d, rssi:%d",
  230. cell_index,
  231. cell_info->lte_info[cell_index].flag,
  232. cell_info->lte_info[cell_index].cid,
  233. cell_info->lte_info[cell_index].mcc,
  234. cell_info->lte_info[cell_index].mnc,
  235. cell_info->lte_info[cell_index].tac,
  236. cell_info->lte_info[cell_index].pci,
  237. cell_info->lte_info[cell_index].earfcn,
  238. cell_info->lte_info[cell_index].rssi);
  239. }
  240. }
  241. #ifdef QL_APP_FEATURE_JAMDET
  242. ret = ql_nw_get_jamdet_status(sim_id, &jamdet_status);
  243. QL_NW_DEMO_LOG("ret=0x%x, jamdet_status:%d", ret, jamdet_status);
  244. #endif
  245. ret = ql_nw_get_emm_gmm_cause(&cause);
  246. QL_NW_DEMO_LOG("get emm/gmm cause,ret=0x%x",ret);
  247. ql_nw_cause_print(&cause);
  248. ret = ql_nw_get_esm_sm_cause(&cause);
  249. QL_NW_DEMO_LOG("get esm/sm cause,ret=0x%x",ret);
  250. ql_nw_cause_print(&cause);
  251. QL_NW_DEMO_LOG("====================nw demo end===================");
  252. }
  253. exit:
  254. if(NULL != reg_info)
  255. free(reg_info);
  256. if(NULL != signal_info)
  257. free(signal_info);
  258. if(NULL != oper_info)
  259. free(oper_info);
  260. if(NULL != select_info)
  261. free(select_info);
  262. if(NULL != nitz_info)
  263. free(nitz_info);
  264. if(NULL != cell_info)
  265. free(cell_info);
  266. err = ql_rtos_task_delete(NULL);
  267. if(err != QL_OSI_SUCCESS)
  268. {
  269. QL_NW_DEMO_LOG("task deleted failed");
  270. }
  271. }
  272. void ql_nw_app_init(void)
  273. {
  274. QlOSStatus err = QL_OSI_SUCCESS;
  275. err = ql_rtos_task_create(&nw_task, 1024*4, APP_PRIORITY_NORMAL, "QNWDEMO", nw_app_thread, NULL, 5);
  276. if(err != QL_OSI_SUCCESS)
  277. {
  278. QL_NW_DEMO_LOG("created task failed");
  279. }
  280. }