blob: 265978a4b3fd2f1dcb35107ddaa6338bcdbef002 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#include "kal_public_api.h"
2#ifdef __GCC_COMPILER__
3#include <strings.h>
4#endif
5#include <string.h>
6#include "l5_common.h"
7#include "l5_msgid.h"
8#include "custom_l5.h"
9
10
11//type: string type terminated by '\0'
12//value: uint32
13kal_bool l5custom_is_ok_to_write_dipc_config(kal_uint8 *type)
14{
15#if 0
16/* under construction !*/
17/* under construction !*/
18/* under construction !*/
19/* under construction !*/
20#endif
21 return KAL_TRUE;
22}
23
24kal_bool l5custom_is_ok_to_write_nvram(kal_uint32 file_idx)
25{
26#if 0
27/* under construction !*/
28/* under construction !*/
29/* under construction !*/
30/* under construction !*/
31#endif
32
33 return KAL_FALSE;
34}
35
36typedef struct {
37 kal_char config_type_str[32];
38 kal_bool is_user_sensitive;
39 kal_uint8 valid_ps_id; //bitmap
40 module_type module_id;
41} l5_general_modem_config_struct;
42
43static l5_general_modem_config_struct gmc_table[] = {
44 {"sample", KAL_FALSE, 0xff, MOD_L5IO},
45 {"L5_TO_MMTST", KAL_FALSE, 0xff, MOD_MMRF_XL1TST},
46 {"L5_TO_NL1", KAL_FALSE, 0xff, MOD_NL1},
47};
48
49kal_bool l5_general_modem_configure_req_custom(kal_uint8 ps_id, kal_bool is_set, ilm_struct *ilm_ptr)
50{
51 l5_general_modem_configure_set_req_struct *set_req_ptr;
52 l5_general_modem_configure_get_req_struct *get_req_ptr;
53 //peer_buff_struct *peer_buff_ptr = ilm_ptr->peer_buff_ptr;
54
55 kal_uint32 i, max;
56 char name [32];
57 max = sizeof(gmc_table)/sizeof(l5_general_modem_config_struct);
58
59 if (is_set) { //set
60 set_req_ptr = (l5_general_modem_configure_set_req_struct *)ilm_ptr->local_para_ptr;
61 memcpy(name, (char *)set_req_ptr->config_type, sizeof(name));
62 } else { //query
63 get_req_ptr = (l5_general_modem_configure_get_req_struct *)ilm_ptr->local_para_ptr;
64 memcpy(name, (char *)get_req_ptr->config_type, sizeof(name));
65 }
66
67 for (i = 0; i < max; i++) {
68 if (strcasecmp((char *)gmc_table[i].config_type_str, name) == 0) {
69 if (gmc_table[i].valid_ps_id & (1 << ps_id)) {
70 //set destination module id
71 ilm_ptr->dest_mod_id = gmc_table[i].module_id + ps_id;
72
73 if (gmc_table[i].is_user_sensitive) {
74 //ilm_ptr->sap_id =
75 }
76
77 //customization here if necessary
78 if (is_set) { //set operation
79
80 } else { //get operation
81
82 }
83
84 return KAL_TRUE;
85 } else {
86 return KAL_FALSE;
87 }
88 }
89
90 }
91
92 return KAL_FALSE;
93}
94
95//this is just for the init function in boot procedure. also can be cfg after boot up
96//this function only config for <new sms storage> and <read msg> and <write msg>. <new cell broadcast>&<new status report> only support save in HOST now
97//Even prefer not save in HOST, some special SMS would not save in DEVICE(and use MIPC_IND/CMD to indicate HOST), like supl msg, refer to custom_l5_sms_force_relay_to_HOST
98kal_uint8 custom_l5_sms_storage_select_init()
99{
100 return 0; //SM: prefer only save in DEVICE_SIM, new sms would notify HOST(AP, USER) with MIPC_IND which contains memory index
101 // return 1; //ME: prefer save in DEVICE_NVRAM
102 // return 2; //TE: prefer save in HOST, new sms would notify HOST(AP,USER) by MIPC_IND or MIPC_CMD according to ack option
103 // return 4; //MT: prefer save in DEVICE_SIM; if SIM_full or SIM_mem_invalid, then try save in DEVICE_NVRAM
104}
105
106//this is just for the init function in boot procedure. also can be cfg after boot up
107kal_bool custom_l5_sms_need_ack_init()
108{
109 //return KAL_TRUE; //If the new SMS not save in DEVICE(DEVICE relay the raw data to HOST), this option would take effect. MIPC_CMD would be userd to notify HOST(AP,USER) for new SMS/DS
110 return KAL_FALSE; //MIPC_IND would be used to notify HOST(AP, USER) for new SMS/DS
111}
112
113//you can decide what sms should relay to HOST use NEW_SMS_IND/CMD even if config save in DEVICE.
114//If this function return TRUE, SMS would not save in DEVICE and notify HOST using NEW_SMS_IND/CMD according to ack_prefer
115kal_bool custom_l5_sms_force_relay_to_HOST(const kal_uint8* sms_ptr)
116{
117 kal_uint8 idx = 0; //init point to sca_len
118 kal_uint8 first_octer = 0;
119 kal_bool tp_udhi = KAL_FALSE;
120 kal_uint8 oa_len = 0;
121 kal_uint8 udh_l = 0;
122 kal_uint8 udh_idx = 0;
123 kal_bool is_need_relay = KAL_FALSE;
124
125 if(NULL == sms_ptr) {
126 return KAL_FALSE;
127 }
128 idx++; //point to SCA start
129 idx+=sms_ptr[0]; //point to first_octer
130 first_octer = sms_ptr[idx++]; //point to OA_L
131 tp_udhi = 0==(first_octer&0x40) ? KAL_FALSE : KAL_TRUE;
132 oa_len = sms_ptr[idx];
133 idx+=(1 + 1 + (oa_len+1)/2); //point to PID
134 idx++; //point to DCS
135 //class0 need to relay, this is in MBIM spec
136 if(0x10 == (sms_ptr[idx] & 0x13)) return KAL_TRUE;
137 idx++; //point to SCTS
138 idx+=7; //point to UDL
139 if(KAL_TRUE == tp_udhi) {
140 idx++; //point to UDH_L
141 udh_l = sms_ptr[idx];
142 for (udh_idx = 1; udh_idx < udh_l; udh_idx++){
143 //16-bit application port
144 if(0x05 == sms_ptr[idx+udh_idx] && 4 == sms_ptr[idx+udh_idx+1]) {
145 // TODO: Discuss with SMS user to confirm jugde standard
146 kal_uint16 dest_port = (((kal_uint16)(sms_ptr[idx+udh_idx+2]))<<8) + sms_ptr[idx+udh_idx+3];
147 //using last valid port to judge
148 if(7275 == dest_port || 2948 == dest_port) is_need_relay = KAL_TRUE;
149 else is_need_relay = KAL_FALSE;
150 }
151 udh_idx+=(1+sms_ptr[idx+udh_idx+1]);
152 }
153 }
154 return is_need_relay;
155}
156
157// with MBIM project, we would transfer the 3gpp2_mt_sms -> 3gpp_mt_sms, then save the 3gpp_mt_sms in DEVICE
158// you can decide what sms should relay to HOST use NEW_SMS_IND even if config save in DEVICE.
159// currently the format follow CS.0015
160// though not support C2K, but datacard project could recv 3gpp2 format SMS using IMS. this api is for 3gpp2 format MT sms.
161kal_bool custom_l5_sms_force_relay_to_HOST_3gpp2(const kal_uint8* c2k_ptr, kal_uint8 pdu_len)
162{
163 kal_uint16 c2k_idx=1;
164
165 for(;c2k_idx<pdu_len;c2k_idx++){
166 // get Message Identifier tlv first
167 if(0x00 == c2k_ptr[c2k_idx]) {
168 // if PUSH msg, force relay
169 if(c2k_idx+3<pdu_len && 2 == c2k_ptr[c2k_idx+1] && 0x10 == c2k_ptr[c2k_idx+2] && 0x04 == c2k_ptr[c2k_idx+3]){
170 return KAL_TRUE;
171 } else {
172 return KAL_FALSE;
173 }
174 }
175 c2k_idx += (c2k_ptr[c2k_idx+1]+1);
176 }
177 return KAL_FALSE;
178}
179
180kal_bool custom_l5_custom_device_caps(l5_custom_device_cap_info_struct *device_caps)
181{
182 /*
183 * If any data of device_caps has been modified, return KAL_TRUE
184 * Example:
185 * device_caps->device_type = 3;
186 * return KAL_TRUE;
187 * If there is no any modification for data of device_cap, return KAL_FALSE
188 */
189 return KAL_FALSE;
190}
191
192kal_bool custom_l5_custom_provider_name(kal_uint8 *provider_name, kal_uint16 *len, kal_uint32 sbp_id)
193{
194 /*
195 * If provider_name have assigned value, return KAL_TRUE
196 * Example:
197 * Please provide the buff data
198 * MTK will not do any processing on buff data
199 * switch (sbp_id) {
200 * case 2:
201 * kal_uint8 buff[] = {0x41, 0x00, 0x42, 0x00, 0x43, 0x00};
202 * memcpy(provider_name, buff, sizeof(buff));
203 * *len = sizeof(buff);
204 * break;
205 * case 3:
206 * kal_uint8 buff[] = {0x2d, 0x4e, 0xfd, 0x56};
207 * memcpy(provider_name, buff, sizeof(buff));
208 * *len = sizeof(buff);
209 * break;
210 * default:
211 * return KAL_FALSE;
212 * }
213 * return KAL_TRUE;
214 *
215 * If there is no any assignment, return KAL_FALSE
216 */
217
218 return KAL_FALSE;
219}
220
221kal_bool custom_l5_signal_state_rsrp_threshold(uint32_t *rsrp_threshold)
222{
223 /*
224 * If rsrp_threshold have assigned value, return KAL_TRUE
225 * Example:
226 * *rsrp_threshold = 5; (Value should not be less than 0)
227 * return KAL_TRUE;
228 * If there is no any assignment, return KAL_FALSE
229 */
230 return KAL_FALSE;
231}
232
233kal_bool custom_l5_packet_service_speed(uint32_t data_class, kal_uint64 *uplink_speed_ptr, kal_uint64 *downlink_speed_ptr)
234{
235 /*
236 * If uplink_speed_ptr and downlink_speed_ptr have assigned values, return KAL_TRUE
237 * Example:
238 * *uplink_speed_ptr = 250000000;
239 * *downlink_speed_ptr = 500000000;
240 * return KAL_TRUE;
241 * If there is no any assignment, return KAL_FALSE
242 */
243 return KAL_FALSE;
244}
245
246kal_bool custom_l5_nw_enable_EONS()
247{
248 /*
249 *If you want to enable EONS, return KAL_TRUE
250 *If there is no need to enable EONS, return KAL_FALSE
251 */
252 return KAL_FALSE;
253}
254
255/******************************************************************************
256**if you want to disable one or more rat, please modify this array
257** 0 means don't disable the rat
258** 1 means disable the rat
259*******************************************************************************/
260#if 0
261/* under construction !*/
262/* under construction !*/
263/* under construction !*/
264/* under construction !*/
265/* under construction !*/
266/* under construction !*/
267/* under construction !*/
268/* under construction !*/
269/* under construction !*/
270/* under construction !*/
271/* under construction !*/
272/* under construction !*/
273/* under construction !*/
274/* under construction !*/
275/* under construction !*/
276/* under construction !*/
277/* under construction !*/
278/* under construction !*/
279/* under construction !*/
280/* under construction !*/
281/* under construction !*/
282/* under construction !*/
283#endif
284
285kal_bool custom_l5_nw_enable_EDMFAPP_6_3()
286{
287 /*
288 If you want to enable EDMFAPP_6_3, return KAL_TRUE, else return KAL_FALSE
289 */
290 return KAL_FALSE;
291}
292
293kal_bool custom_l5_signal_check(l5_custom_signal_state *signal_state)
294{
295 if(signal_state->rsrp_snr_count != 0)
296 {
297 for(int i = 0; i < signal_state->rsrp_snr_count; i++)
298 {
299 if(signal_state->signal[i].rsrp_dbm >= -99)
300 signal_state->signal[i].rsrp = 5;
301 else if(signal_state->signal[i].rsrp_dbm >= -109 && -99 > signal_state->signal[i].rsrp_dbm)
302 signal_state->signal[i].rsrp = 4;
303 else if(signal_state->signal[i].rsrp_dbm >= -114 && -109 > signal_state->signal[i].rsrp_dbm)
304 signal_state->signal[i].rsrp = 3;
305 else if(signal_state->signal[i].rsrp_dbm >= -119 && -114 > signal_state->signal[i].rsrp_dbm)
306 signal_state->signal[i].rsrp = 2;
307 else if(signal_state->signal[i].rsrp_dbm >= -120 && -119 > signal_state->signal[i].rsrp_dbm)
308 signal_state->signal[i].rsrp = 1;
309 else if(-120 > signal_state->signal[i].rsrp_dbm)
310 signal_state->signal[i].rsrp = 0;
311 }
312 }
313
314 /* If any data of signal has been modified, return KAL_TRUE */
315 return KAL_FALSE;
316}
317
318typedef struct{
319kal_uint32 type;
320kal_uint32 len;
321kal_uint32 tid;
322} l5_msg_header;
323
324void custom_l5_MBIM_message(void* message_buffer, uint32_t msg_length)
325{
326 l5_msg_header* p = (l5_msg_header *)message_buffer;
327 kal_prompt_trace(MOD_L5IO, "MBIM_TYPE:%u, MBIM_LEN:%u, MBIM_TID:%u", p->type, p->len, p->tid);
328
329 return;
330}
331
332//The example of the mapping array for the oper_name by plmn_id and gid1.
333//the list is the customized,offical release will be comment out.
334l5u_oper_name_mapping_item g_l5u_oper_name_mapping_table[] = {
335// plmn_id gid1 gid1_length oper_name
336 {"23430", {0xee}, 1, "EE"},
337 {"23433", {0xff}, 1, "FF"},
338 {"23430", {0xc3}, 1, "BT"},
339 {"23433", {0xb3}, 1, "BT"},
340};
341
342/*
343This func just a example, Customer can redefine implementation method and mapping list according to their own needs.
344*/
345kal_bool custom_l5_oper_name_mapping_by_gid1(kal_char *oper_name, kal_char *plmn_id, kal_uint8 plmn_length, kal_uint8 *gid1, kal_uint8 gid1_max_length)
346{
347 kal_uint32 mapping_table_size = 0;
348 kal_uint32 index = 0;
349 kal_uint8 i = 0;
350 kal_bool result = KAL_FALSE;
351 //kal_uint8 gid1_length = 0;
352 kal_bool is_gid1_match = KAL_TRUE;
353 //kal_uint32 p_gid1 = 0;
354/*
355 The pointer plmn_id and gid1 points to the value of plmn and gid1,whitch map to the oper_name in the mapping list.
356 if call the func ,it will select the mapping list, and map to oper_name accprding to plmn_id and gid1.
357 if find in the list,it will be return KAL_TRUE; otherwise return KAL_FALSE.
358
359 Example:
360 If you get a valid oper_name from the list ,
361 memcpy(oper_name, g_l5u_oper_name_mapping_table[index].oper_name, sizeof(oper_name));
362 return KAL_TRUE;
363 If there can't get valid oper_name:
364 return KAL_FALSE;
365
366 The example code as follow:
367 **this is just a demo,customer shoult according their needs to coding by themself.
368*/
369 mapping_table_size = (kal_uint32)sizeof(g_l5u_oper_name_mapping_table)/sizeof(g_l5u_oper_name_mapping_table[0]);
370 for (; index <= mapping_table_size - 1; index++) {
371 for (; i <= g_l5u_oper_name_mapping_table[index].gid1_length - 1; i++) {
372 if (g_l5u_oper_name_mapping_table[index].gid1[i] == gid1[i]) {
373 continue;
374 } else {
375 is_gid1_match = KAL_FALSE;
376 break;
377 }
378 }
379 if ((strncmp(g_l5u_oper_name_mapping_table[index].plmn_id, plmn_id,
380 sizeof(g_l5u_oper_name_mapping_table[index].plmn_id) > plmn_length ? plmn_length : sizeof(g_l5u_oper_name_mapping_table[index].plmn_id)) == 0)
381 && is_gid1_match == KAL_TRUE) {
382 memcpy(oper_name, g_l5u_oper_name_mapping_table[index].oper_name, strlen(g_l5u_oper_name_mapping_table[index].oper_name));
383 result = KAL_TRUE;
384 break;
385 }
386 }
387 return result;
388}
389
390/******************************************************************************
391**You can modify this fuction to choose the mode of 5g icon display
392*******************************************************************************/
393kal_uint32 custom_l5_get_5g_icon_display_mode()
394{
395#if 0
396/* under construction !*/
397/* under construction !*/
398/* under construction !*/
399/* under construction !*/
400/* under construction !*/
401/* under construction !*/
402/* under construction !*/
403/* under construction !*/
404/* under construction !*/
405/* under construction !*/
406/* under construction !*/
407/* under construction !*/
408/* under construction !*/
409/* under construction !*/
410/* under construction !*/
411/* under construction !*/
412/* under construction !*/
413/* under construction !*/
414/* under construction !*/
415/* under construction !*/
416/* under construction !*/
417/* under construction !*/
418/* under construction !*/
419/* under construction !*/
420/* under construction !*/
421/* under construction !*/
422/* under construction !*/
423/* under construction !*/
424/* under construction !*/
425/* under construction !*/
426#endif
427 return L5_5G_ICON_MODE_JP;
428}