blob: 32ffc94590276d0f505a242f155cac9140a3e4d6 [file] [log] [blame]
b.liu86b7ff22024-04-03 14:25:55 +08001#include "lynq_qser_network.h"
2#include "mbtk_type.h"
3#include "mbtk_info_api.h"
4
5#include <stdio.h>
6#include <stdlib.h>
7
8
9char *tech_domain[] = {"NONE", "3GPP", "3GPP2"};
10char *radio_tech[] = {"unknown",
11 "TD_SCDMA", "GSM", "HSPAP", "LTE", "EHRPD", "EVDO_B",
12 "HSPA", "HSUPA", "HSDPA", "EVDO_A", "EVDO_0", "1xRTT",
13 "IS95B", "IS95A", "UMTS", "EDGE", "GPRS", "NONE"};
14
15void nw_event_ind_handler (
16 nw_client_handle_type h_nw,
17 u_int32_t ind_flag,
18 void *ind_msg_buf,
19 u_int32_t ind_msg_len,
20 void *contextPtr)
21{
22 uint8 *net_data = NULL;
23
24 net_data = (uint8*)ind_msg_buf;
25
26 if(ind_msg_buf && ind_msg_len > 0)//无处理原始数据传输过来
27 {
28 if(*net_data == 0)
29 { // CS
30 printf("CS:act=%d, mode=%d\n", *(net_data + 1), *(net_data + 2));
31 }
32 else
33 { // PS
34 printf("PS[%s]:act=%d, mode=%d\n", *(net_data + 3) == 0 ? "GSM/WCDMA" : "LTE", *(net_data + 1), *(net_data + 2));
35 }
36 }
37 else
38 {
39 printf("NET_CB : NULL");
40 }
41
42}
43
44
45int main(int argc, char *argv[])
46{
47 char operator[10];
48 int opt;
49 int lv_voll = 0;
r.xiaoba8483c2024-04-14 18:53:10 -070050 int ret;
b.liu86b7ff22024-04-03 14:25:55 +080051 nw_client_handle_type handle = -1;
52 mbtk_log_init("radio", "NW_TEST");
53
r.xiaoba8483c2024-04-14 18:53:10 -070054 printf("=========network main=========\n"
55 "\t0 exit\n"
56 "\t1 network init\n"
57 "\t2 network add rx msg handle\n"
58 "\t3 network band set config\n"
59 "\t4 network get operator name\n"
60 "\t5 network get reg status\n"
61 "\t6 network get signal strength\n"
62 "\t7 network set oos config\n"
63 "\t8 network get oos config\n"
64 "\t9 network set rf config\n"
65 "\t10 network get rf config\n"
66 "\t11 network set ims config\n"
67 "\t12 network get ims config\n"
68 "\t13 network deinit\n"
69 "operator: >> ");
70
b.liu86b7ff22024-04-03 14:25:55 +080071 while(1)
72 {
b.liu86b7ff22024-04-03 14:25:55 +080073
r.xiaoba8483c2024-04-14 18:53:10 -070074 opt = -1;
b.liu86b7ff22024-04-03 14:25:55 +080075 fgets(operator, sizeof(operator), stdin);
76 fflush(stdin);
77 opt = atoi(operator);
78 switch (opt)
79 {
80 case 0:
81 printf("main exit\n");
82 return 0;
83 case 1:
r.xiaoba8483c2024-04-14 18:53:10 -070084 ret = qser_nw_client_init(&handle);
85 printf("qser_nw_client_init ret = %d\n", ret);
b.liu86b7ff22024-04-03 14:25:55 +080086 break;
87 case 2:
r.xiaoba8483c2024-04-14 18:53:10 -070088 ret = qser_nw_add_rx_msg_handler(handle, nw_event_ind_handler, NULL);
89 printf("qser_nw_add_rx_msg_handler ret = %d\n", ret);
b.liu86b7ff22024-04-03 14:25:55 +080090 break;
91 case 3:
92 {
93 //漫游开关现在不支持,所以就不用配置
94 printf("please input \n"
95 "\t1:GSM \n"
96 "\t2:WCDMA \n"
97 "\t4:CDMA \n"
98 "\t8:EVDO \n"
99 "\t16:LTE \n"
100 "\t32:TDSCDMA \n"
101 );
102 memset(operator,0x00, sizeof(operator));
103 fgets(operator, sizeof(operator)-1, stdin);
104 fflush(stdin);
105 opt = atoi(operator);
106 QSER_NW_CONFIG_INFO_T t_info;
107 switch(opt)
108 {
109 case 1:
110 t_info.preferred_nw_mode = QSER_NW_MODE_GSM;//2G
111 break;
112 case 2:
113 t_info.preferred_nw_mode = QSER_NW_MODE_WCDMA;//3G
114 break;
115 case 4:
116 t_info.preferred_nw_mode = QSER_NW_MODE_CDMA;//3G
117 break;
118 case 8:
119 t_info.preferred_nw_mode = QSER_NW_MODE_EVDO;//3G
120 break;
121 case 16:
122 t_info.preferred_nw_mode = QSER_NW_MODE_LTE;//4G
123 break;
124 case 32:
125 t_info.preferred_nw_mode = QSER_NW_MODE_TDSCDMA;//3G
126 break;
127 default:
128 t_info.preferred_nw_mode = QSER_NW_MODE_LTE;//4G
129 break;
130 }
r.xiaoba8483c2024-04-14 18:53:10 -0700131 ret = qser_nw_set_config(handle, &t_info);
132 printf("qser_nw_set_config ret = %d\n", ret);
b.liu86b7ff22024-04-03 14:25:55 +0800133 }
134 break;
135 case 4:
136 {
137 QSER_NW_OPERATOR_NAME_INFO_T t_info;
138 int err = qser_nw_get_operator_name(handle, &t_info);
139 if(err)
140 {
141 printf("Error : %d\n", err);
142 } else
143 {
144 printf("Operator : %s, %s, %s, %s\n", t_info.long_eons, t_info.short_eons, t_info.mcc, t_info.mnc);
145 }
146 }
147 break;
148 case 5:
149 {
150 QSER_NW_REG_STATUS_INFO_T reg;
151 int err = qser_nw_get_reg_status(handle, &reg);
152 if(err)
153 {
154 printf("Error : %d\n", err);
155 }
156 else
157 {
158 if(reg.voice_registration_details_3gpp_valid)
159 {
160 printf("voice_registration_details_3gpp: tech_domain=%d, radio_tech=%d, mcc=%s, mnc=%s, roaming=%d, forbidden=%d, cid=0x%X, lac=%d, psc=%d, tac=%d\n",
161 reg.voice_registration_details_3gpp.tech_domain,
162 reg.voice_registration_details_3gpp.radio_tech,
163 reg.voice_registration_details_3gpp.mcc,
164 reg.voice_registration_details_3gpp.mnc,
165 reg.voice_registration_details_3gpp.roaming,
166 reg.voice_registration_details_3gpp.forbidden,
167 reg.voice_registration_details_3gpp.cid,
168 reg.voice_registration_details_3gpp.lac,
169 reg.voice_registration_details_3gpp.psc,
170 reg.voice_registration_details_3gpp.tac);
171 }
172 if(reg.data_registration_details_3gpp_valid)
173 {
174 printf("data_registration_details_3gpp: tech_domain=%d, radio_tech=%d, mcc=%s, mnc=%s, roaming=%d, forbidden=%d, cid=0x%X, lac=%d, psc=%d, tac=%d\n",
175 reg.data_registration_details_3gpp.tech_domain,
176 reg.data_registration_details_3gpp.radio_tech,
177 reg.data_registration_details_3gpp.mcc,
178 reg.data_registration_details_3gpp.mnc,
179 reg.data_registration_details_3gpp.roaming,
180 reg.data_registration_details_3gpp.forbidden,
181 reg.data_registration_details_3gpp.cid,
182 reg.data_registration_details_3gpp.lac,
183 reg.data_registration_details_3gpp.psc,
184 reg.data_registration_details_3gpp.tac);
185 }
186 //printf("Data Reg: radio_tech = %d, lac = %x, cid = %x\n", reg.data_registration_details_3gpp.radio_tech, reg.data_registration_details_3gpp.lac, reg.data_registration_details_3gpp.cid);
187 //printf("Voice Reg: radio_tech = %d, lac = %x, cid = %x\n", reg.voice_registration_details_3gpp.radio_tech, reg.voice_registration_details_3gpp.lac, reg.voice_registration_details_3gpp.cid);
188 }
189 }
190 break;
191 case 6:
192 {
193 QSER_NW_SIGNAL_STRENGTH_INFO_T sig;
194 int err = qser_nw_get_signal_strength(handle, &sig);
195 if(err)
196 {
197 printf("Error : %d\n", err);
198 }
199 else
200 {
201 if (sig.gsm_sig_info_valid == TRUE)
202 printf("Signal GSM: rssi = %d\n", sig.gsm_sig_info.rssi);
203 else if (sig.lte_sig_info_valid == TRUE)
204 printf("Signal LTE: rssi = %d, rsrp = %d, rsrq = %d, snr = %d\n", sig.lte_sig_info.rssi , sig.lte_sig_info.rsrp, sig.lte_sig_info.rsrq, sig.lte_sig_info.snr);
205 else if (sig.wcdma_sig_info_valid == TRUE)
206 printf("Signal UTRAN: rssi = %d, ecio = %d\n", sig.wcdma_sig_info.rssi , sig.wcdma_sig_info.ecio);
207 else
208 printf("Signal type not supported \n");
209 }
210 }
211 break;
212 case 7:
213 {
214 QSER_NW_OOS_CONFIG_INFO_T pt_info_s;
215 memset(&pt_info_s, 0x00, sizeof(QSER_NW_OOS_CONFIG_INFO_T));
216 /*取值范围0-255,设置时间自定义
217 phase 1 5次 次数无法更改,这五次都是以10秒为一次的间隔搜网
218 phase 2 5次 次数无法更改,这五次都是以15秒为一次的间隔搜网
219 phase 3 不限制次数的秒数设置,第三阶段不限制次数以20秒为一次的间隔搜网
220 如果要关闭OOS配置,则把min step max 全部配置为0即可
221 */
222 pt_info_s.type = QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN;//平台提供自定义配置搜网时间间隔
223 {
224 pt_info_s.u.full_band_scan_info.t_min = 10;//phase 1
225 pt_info_s.u.full_band_scan_info.t_step = 15;//phase 2
226 pt_info_s.u.full_band_scan_info.t_num = 0;//可以不配置,并没有使用
227 pt_info_s.u.full_band_scan_info.t_max = 20;//phase 3
228 }
229 printf("set OOS %d %d %d \n",pt_info_s.u.full_band_scan_info.t_min, pt_info_s.u.full_band_scan_info.t_step, pt_info_s.u.full_band_scan_info.t_max);
230 //pt_info_s.type = QSER_NW_OOS_CFG_TYPE_FAST_SCAN;平台本身有历史频点优先处理的逻辑(无接口不需要我们进行处理)
r.xiaoba8483c2024-04-14 18:53:10 -0700231 ret = qser_nw_set_oos_config(handle, &pt_info_s);
232 printf("qser_nw_set_oos_config ret = %d\n", ret);
b.liu86b7ff22024-04-03 14:25:55 +0800233 }
234 break;
235 case 8:
236 {
237 QSER_NW_OOS_CONFIG_INFO_T pt_info_g;
238 qser_nw_get_oos_config(handle, &pt_info_g);
239 if (pt_info_g.type == QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN)
240 printf("TYPE: %d min: %d setp: %d max: %d\n", pt_info_g.type, pt_info_g.u.full_band_scan_info.t_min, pt_info_g.u.full_band_scan_info.t_step, pt_info_g.u.full_band_scan_info.t_max);
241 else
242 printf("type not supported \n");
243 }
244 break;
245 case 9:
246 {
247 printf("please input 0 or 1 or 4: \n");
248 memset(operator,0x00, sizeof(operator));
249 fgets(operator, sizeof(operator)-1, stdin);
250 fflush(stdin);
251 opt = atoi(operator);
252 printf("rf_mode: [%d]\n",opt);
r.xiaoba8483c2024-04-14 18:53:10 -0700253 ret = qser_nw_set_rf_mode(handle, opt);
254 printf("qser_nw_set_rf_mode ret = %d\n", ret);
b.liu86b7ff22024-04-03 14:25:55 +0800255 }
256 break;
257 case 10:
258 {
259 int rf_t;
260 qser_nw_get_rf_mode(handle, &rf_t);
261 printf(">>>rf_mode = [%d]\n",rf_t);
262 }
263 break;
264 case 11:
r.xiaoba8483c2024-04-14 18:53:10 -0700265 {
266 E_QSER_NW_IMS_MODE_TYPE_T ims_mode;
267 printf("please input you want set ims mode (0: off; 1: volte enable \n");
268 scanf("%d", &ims_mode);
269 ret = qser_nw_set_ims_enable(handle, ims_mode);
270 printf("qser_nw_set_ims_enable %d ret = %d\n",ims_mode, ret);
271 }
272 break;
273 case 12:
274 {
275 QSER_NW_IMS_REG_STATUS_INFO_T t_info;
276 memset(&t_info, 0, sizeof(QSER_NW_IMS_REG_STATUS_INFO_T));
277 ret = qser_nw_get_ims_reg_status(handle, &t_info);
278 printf("qser_nw_get_ims_reg_status ret = %d, detail info:\n", ret);
279 if(ret == 0)
280 {
281 printf("ims_registration: registration_state=%d\n", t_info.registration_state);
282 }
283 }
284 break;
285 case 13:
b.liu86b7ff22024-04-03 14:25:55 +0800286 qser_nw_client_deinit(handle);
287 break;
288 default:
289 break;
290 }
291
292 }
293
294 return 0;
295}
296