blob: 1d70b0aa16368ea21c5224eb2ded0fce5109cce8 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * sbp_utility.c
41 *
42 * Project:
43 * --------
44 * MOLY
45 *
46 * Description:
47 * ------------
48 * This file is intends for SBP definition
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 ****************************************************************************/
56
57#define SBP_UTILITY_C
58
59#include "kal_general_types.h"
60#include "sbp_public_utility.h"
61#include "kal_public_api.h"
62#include "ps_em_enum.h"
63#include "nvram_interface.h"
64#include "nvram_data_items.h"
65#include "sbp_nvram_def.h"
66#include "nvram_enums.h"
67#include "nvram_editor_data_item.h"
68#include "sim_ps_api.h"
69#include "md_sap.h"
70#include "custom_imc_config.h"
71#include "custom_ltecsr_config.h"
72#include "mcf_if.h"
73
74#include "sbp_trc.h"
75#include "kal_trace.h"
76
77#if defined (__TC01_NVRAM__) || defined(__TC01__) //MOLY00294741
78/*MUSE - ALPS0144925 */ /*MOLY00294741*/
79/*Customer's specific Single Binary Platform (SBP) features */
80nvram_ef_sbp_modem_config_struct cust_sbp_config;
81#endif
82
83#define SBP_TEST_MODE_VAL_1 8286
84#define SBP_TEST_MODE_VAL_2 8287
85
86extern sim_interface_enum l4c_gemini_get_actual_sim_id(sim_interface_enum simId);
87extern ps_conf_test_mode_enum query_ps_conf_test_mode(void);
88
89extern kal_uint8 ValCurrentActiveSimIndex();
90void sbp_get_sbp_ids_from_cntxt(nvram_ef_sbp_ids_struct *sbp_ids_ptr);
91
92typedef struct
93{
94 kal_uint32 sbp_id;
95 kal_uint32 sbp_sub_id;
96 kal_uint32 test_mode;
97 kal_uint32 dsbp_mode;
98 nvram_ef_sbp_dsbp_config_struct dsbp_config;
99} sbp_common_context_struct;
100
101typedef struct
102{
103 kal_uint32 current_sim_sbp_id;
104 kal_uint32 dsbp_sim_sbp_id_mode1; // IMS/VoLTE
105 kal_uint32 dsbp_sim_sbp_id_mode2; // All modem
106 kal_uint8 modem_sbp_config[(SBP_MAX_MD_FEATURE/8)+1]; //the size depends on SBP_MAX_MD_FEATURE
107#if defined (__TC01_NVRAM__) || defined(__TC01__) // __TC01_CUST_SBP__
108 kal_uint8 modem_cust_sbp_config[(SBP_CUSTOM_MAX_MD_FEATURE/8)+1]; //the size depends on SBP_MAX_CUST_MD_FEATURE
109#endif
110 kal_uint8 modem_sbp_data_config[SBP_DATA_MAX_MD_FEATURE];
111 kal_uint8 mcc[MAX_MCC_STR_LEN];
112 kal_uint8 mnc[MAX_MNC_STR_LEN];
113 kal_uint8 iccid[21];
114} sbp_context_struct;
115
116#ifdef __IPC_ADAPTER__
117#include "ipca_nvram_def.h"
118sbp_salecode_struct sbp_salecode;
119#endif
120
121kal_uint32 default_sbp_id = SBP_ID_INVALID;
122kal_uint32 default_sbp_sub_id = 0;
123
124nvram_ef_sbp_modem_config_struct sbp_config;
125nvram_ef_sbp_modem_data_config_struct sbp_data_config;
126nvram_ef_sbp_custom_sbp_id_mapping_struct g_custom_sbp_id_mapping_table;
127nvram_ef_sbp_mdcxp_sbp_id_list_struct g_mdcxp_sbp_id_list;
128
129static sbp_common_context_struct sbp_common_cntxt_g;
130static sbp_context_struct sbp_cntxt_g[MAX_SIM_NUM];
131
132/*****************************************************************************
133 * FUNCTION
134 * sbp_get_dsbp_mode
135 *
136 * DESCRIPTION
137 * query dynamic SBP mode
138 *
139 * PARAMETERS
140 * [IN] N/A
141 * RETURNS
142 * current DSBP mode : l4bsbp_dsbp_mode_enum
143 *****************************************************************************/
144kal_uint8 sbp_get_dsbp_mode (void)
145{
146 return (kal_uint8) sbp_common_cntxt_g.dsbp_mode;
147}
148
149/*****************************************************************************
150 * FUNCTION
151 * sbp_set_dsbp_mode
152 *
153 * DESCRIPTION
154 * Set dynamic SBP mode.
155 *
156 * PARAMETERS
157 * dsbp_mdoe [IN] l4bsbp_dsbp_mode_enum
158 * RETURNS
159 * KAL_TRUE : success
160 * KAL_FALSE : fail
161 *****************************************************************************/
162kal_bool sbp_set_dsbp_mode (kal_uint8 dspb_mode)
163{
164 kal_bool result = KAL_TRUE;
165#ifdef __IPC_ADAPTER__
166 nvram_ef_sbp_dsbp_info_struct dsbp_info_buf;
167
168 result = nvram_external_read_data(NVRAM_EF_SBP_DSBP_INFO_LID,
169 1,
170 (kal_uint8*) &dsbp_info_buf,
171 NVRAM_EF_SBP_DSBP_INFO_SIZE);
172
173 if (result == KAL_TRUE)
174 {
175 sbp_common_cntxt_g.dsbp_mode = (kal_uint32) dspb_mode;
176 dsbp_info_buf.default_dsbp_mode = dspb_mode;
177 result = nvram_external_write_data(NVRAM_EF_SBP_DSBP_INFO_LID,
178 1,
179 (kal_uint8*) &dsbp_info_buf,
180 NVRAM_EF_SBP_DSBP_INFO_SIZE);
181 }
182#else
183 nvram_ef_sbp_ids_struct sbp_id_buf;
184
185 sbp_common_cntxt_g.dsbp_mode = (kal_uint32) dspb_mode;
186 // fill LID info from current context
187 sbp_get_sbp_ids_from_cntxt(&sbp_id_buf);
188
189 result = nvram_external_write_data(NVRAM_EF_SBP_IDS_LID,
190 1,
191 (kal_uint8*) &sbp_id_buf,
192 NVRAM_EF_SBP_IDS_SIZE);
193#endif
194
195 return result;
196}
197
198/*****************************************************************************
199 * FUNCTION
200 * sbp_get_test_mode
201 *
202 * DESCRIPTION
203 * query if it is under test mode or not
204 *
205 * PARAMETERS
206 * [IN] N/A
207 * RETURNS
208 * current SBP test mode : sbp_test_mode_enum
209 *****************************************************************************/
210sbp_test_mode_enum sbp_get_test_mode (void)
211{
212 if (sbp_common_cntxt_g.test_mode == SBP_TEST_MODE_VAL_1)
213 return SBP_TEST_MODE_1;
214 else if (sbp_common_cntxt_g.test_mode == SBP_TEST_MODE_VAL_2)
215 return SBP_TEST_MODE_2;
216 else
217 return SBP_TEST_MODE_NONE;
218}
219
220/*****************************************************************************
221 * FUNCTION
222 * sbp_set_test_mode
223 *
224 * DESCRIPTION
225 * Set SBP to test mode.
226 * In test mode, we read current values of nvram files instead of using default values before applying SBP settings.
227 *
228 * PARAMETERS
229 * test_mdoe [IN] sbp_test_mode_enum
230 * RETURNS
231 * KAL_TRUE : success
232 * KAL_FALSE : fail
233 *****************************************************************************/
234kal_bool sbp_set_test_mode (sbp_test_mode_enum test_mode)
235{
236 nvram_ef_sbp_ids_struct sbp_id_buf;
237 kal_bool result = KAL_TRUE;
238
239 if (test_mode == SBP_TEST_MODE_NONE)
240 sbp_common_cntxt_g.test_mode = 0;
241 else if (test_mode == SBP_TEST_MODE_1)
242 sbp_common_cntxt_g.test_mode = SBP_TEST_MODE_VAL_1;
243 else if (test_mode == SBP_TEST_MODE_2)
244 sbp_common_cntxt_g.test_mode = SBP_TEST_MODE_VAL_2;
245
246 // fill LID info from current context
247 sbp_get_sbp_ids_from_cntxt(&sbp_id_buf);
248
249 result = nvram_external_write_data(NVRAM_EF_SBP_IDS_LID,
250 1,
251 (kal_uint8*) &sbp_id_buf,
252 NVRAM_EF_SBP_IDS_SIZE);
253
254 return result;
255
256}
257
258/*****************************************************************************
259* FUNCTION
260* sbp_query_md_feature()
261*
262* DESCRIPTION
263* This function is used to query modem configuration
264*
265* PARAMETERS
266* feature [IN] modem feature
267*
268* RETURNS
269* KAL_TRUE : if this feature is turned on
270* KAL_FALSE : if this feature is turned off
271*****************************************************************************/
272kal_bool sbp_query_md_feature(sbp_md_feature_enum feature)
273{
274 return sbp_query_md_feature_by_ps(feature, PROTOCOL_1);
275}
276
277#ifdef __CDMA2000_RAT__
278/*****************************************************************************
279* FUNCTION
280* sbp_query_md_feature_for_c2k()
281*
282* DESCRIPTION
283* This function is used to query modem configuration and used by C2K team only
284* The function will judge current active PS using C2K's API and return the corresponding setting.
285*
286* PARAMETERS
287* feature [IN] modem feature
288*
289* RETURNS
290* KAL_TRUE : if this feature is turned on
291* KAL_FALSE : if this feature is turned off
292*****************************************************************************/
293kal_bool sbp_query_md_feature_for_c2k(sbp_md_feature_enum feature)
294{
295 protocol_id_enum ps_id = ValCurrentActiveSimIndex();
296
297 if (ps_id >= MAX_SIM_NUM)
298 {
299 #ifndef __L1_STANDALONE__
300 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
301 #endif
302 return KAL_FALSE;
303 }
304
305 return sbp_query_md_feature_by_ps(feature, ps_id);
306}
307#endif
308
309/*****************************************************************************
310* FUNCTION
311* sbp_query_md_feature_by_ps()
312*
313* DESCRIPTION
314* This function is used to query modem configuration according to the PS ID
315*
316* PARAMETERS
317* feature [IN] modem feature
318* ps_id [IN] PS ID
319*
320* RETURNS
321* KAL_TRUE : if this feature is turned on
322* KAL_FALSE : if this feature is turned off
323*****************************************************************************/
324kal_bool sbp_query_md_feature_by_ps(sbp_md_feature_enum feature, protocol_id_enum ps_id)
325{
326 kal_uint8 *bitmask_ptr;
327 kal_uint32 byte_offset;
328 kal_uint8 bit_offset;
329 kal_bool result;
330#ifndef __L1_STANDALONE__
331 static sbp_md_feature_enum latest_queried_sbp[MAX_SIM_NUM];
332#endif
333
334
335 if (feature >= SBP_MAX_MD_FEATURE)
336 {
337 DEBUG_ASSERT(0);
338 return KAL_FALSE;
339 }
340 if (ps_id >=MAX_SIM_NUM)
341 {
342#ifndef __L1_STANDALONE__
343 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
344#endif
345 return KAL_FALSE;
346 }
347
348 byte_offset = feature / 8;
349 bit_offset = feature % 8;
350 bitmask_ptr = &(sbp_cntxt_g[ps_id].modem_sbp_config[byte_offset]);
351
352 result = (((*bitmask_ptr) & (0x01 << bit_offset)) != 0)? KAL_TRUE : KAL_FALSE;
353
354 //For GCF or other test modes, you may overwrite the result.
355 result = sbp_md_feature_overwrite(feature, result);
356
357#ifndef __L1_STANDALONE__
358 if (latest_queried_sbp[ps_id] != feature)
359 {
360 MD_TRC_INFO_SBP_FEATURE(ps_id, feature, result);
361 latest_queried_sbp[ps_id] = feature;
362 }
363#endif
364
365 return result;
366}
367
368
369/*****************************************************************************
370* FUNCTION
371* sbp_query_md_feature_no_overwrite()
372*
373* DESCRIPTION
374* This function is used to query modem configuration without overwrite
375*
376* PARAMETERS
377* feature [IN] modem feature
378*
379* RETURNS
380* KAL_TRUE : if this feature is turned on
381* KAL_FALSE : if this feature is turned off
382*****************************************************************************/
383kal_bool sbp_query_md_feature_no_overwrite(sbp_md_feature_enum feature)
384{
385 return sbp_query_md_feature_no_overwrite_by_ps(feature, PROTOCOL_1);
386}
387
388/*****************************************************************************
389* FUNCTION
390* sbp_query_md_feature_no_overwrite_by_ps()
391*
392* DESCRIPTION
393* This function is used to query modem configuration without overwrite according to the PS ID
394*
395* PARAMETERS
396* feature [IN] modem feature
397* ps_id [IN] PS ID
398*
399* RETURNS
400* KAL_TRUE : if this feature is turned on
401* KAL_FALSE : if this feature is turned off
402*****************************************************************************/
403kal_bool sbp_query_md_feature_no_overwrite_by_ps(sbp_md_feature_enum feature, protocol_id_enum ps_id)
404{
405 kal_uint8 *bitmask_ptr;
406 kal_uint32 byte_offset;
407 kal_uint8 bit_offset;
408 kal_bool result;
409
410#ifndef __L1_STANDALONE__
411 static sbp_md_feature_enum latest_queried_sbp[MAX_SIM_NUM];
412#endif
413
414 if (feature >= SBP_MAX_MD_FEATURE)
415 {
416 DEBUG_ASSERT(0);
417 return KAL_FALSE;
418 }
419 if (ps_id >=MAX_SIM_NUM)
420 {
421#ifndef __L1_STANDALONE__
422 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
423#endif
424 return KAL_FALSE;
425 }
426
427 byte_offset = feature / 8;
428 bit_offset = feature % 8;
429 bitmask_ptr = &(sbp_cntxt_g[ps_id].modem_sbp_config[byte_offset]);
430
431 result = (((*bitmask_ptr) & (0x01 << bit_offset)) != 0)? KAL_TRUE : KAL_FALSE;
432
433#ifndef __L1_STANDALONE__
434 if (latest_queried_sbp[ps_id] != feature)
435 {
436 MD_TRC_INFO_SBP_FEATURE(ps_id, feature, result);
437 latest_queried_sbp[ps_id] = feature;
438 }
439#endif
440
441
442 return result;
443}
444
445
446/*****************************************************************************
447* FUNCTION
448* sbp_set_md_feature()
449*
450* DESCRIPTION
451* This function is used to set modem configuration
452*
453* PARAMETERS
454* feature [IN] modem feature
455* is_turned_on [IN]
456* sbp_feature_ptr [IN/OUT]
457*
458* RETURNS
459* KAL_TRUE if success; otherwise KAL_FALSE
460*****************************************************************************/
461kal_bool sbp_set_md_feature(sbp_md_feature_enum feature,
462 kal_bool is_turned_on,
463 nvram_ef_sbp_modem_config_struct *sbp_feature_ptr)
464{
465 kal_uint8 *bitmask_ptr;
466 kal_uint32 byte_offset;
467 kal_uint8 bit_offset;
468
469
470 if (feature >= SBP_MAX_MD_FEATURE)
471 {
472 return KAL_FALSE;
473 }
474 else
475 {
476 byte_offset = feature / 8;
477 bit_offset = feature % 8;
478 bitmask_ptr = &(sbp_feature_ptr->modem_sbp_config[byte_offset]);
479 if (is_turned_on == KAL_TRUE)
480 {
481 *bitmask_ptr = ((*bitmask_ptr) | (0x01 << bit_offset));
482 }
483 else
484 {
485 *bitmask_ptr = ((*bitmask_ptr) & ~(0x01 << bit_offset));
486 }
487 }
488
489 return KAL_TRUE;
490}
491
492/*****************************************************************************
493* FUNCTION
494* sbp_set_md_feature_by_ps()
495*
496* DESCRIPTION
497* This function is used to set modem configuration by PS
498* Please don't use this API if you don't get the permission from SBP FPM.
499*
500* PARAMETERS
501* feature [IN] modem feature
502* is_turned_on [IN]
503* sbp_feature_ptr [IN/OUT]
504*
505* RETURNS
506* KAL_TRUE if success; otherwise KAL_FALSE
507*****************************************************************************/
508kal_bool sbp_set_md_feature_by_ps(sbp_md_feature_enum feature,
509 kal_bool is_turned_on,
510 protocol_id_enum ps_id)
511{
512 kal_uint8 *bitmask_ptr;
513 kal_uint32 byte_offset;
514 kal_uint8 bit_offset;
515
516 if (feature >= SBP_MAX_MD_FEATURE)
517 {
518 return KAL_FALSE;
519 }
520 else
521 {
522 byte_offset = feature / 8;
523 bit_offset = feature % 8;
524 bitmask_ptr = &(sbp_cntxt_g[ps_id].modem_sbp_config[byte_offset]);
525 if (is_turned_on == KAL_TRUE)
526 {
527 *bitmask_ptr = ((*bitmask_ptr) | (0x01 << bit_offset));
528 }
529 else
530 {
531 *bitmask_ptr = ((*bitmask_ptr) & ~(0x01 << bit_offset));
532 }
533
534#ifndef __L1_STANDALONE__
535 MD_TRC_INFO_SBP_SET_FEATURE(ps_id, feature, is_turned_on);
536#endif
537 }
538
539 return KAL_TRUE;
540}
541
542/*****************************************************************************
543* FUNCTION
544* sbp_general_set_md_feature()
545*
546* DESCRIPTION
547* This function is used to set modem configuration.
548* Please don't use this API if you don't get the permission from SBP FPM.
549*
550* PARAMETERS
551* feature [IN] modem feature
552* is_turned_on [IN]
553*
554* RETURNS
555* KAL_TRUE if success; otherwise KAL_FALSE
556*****************************************************************************/
557kal_bool sbp_general_set_md_feature(sbp_md_feature_enum feature, kal_bool is_turned_on)
558{
559 kal_uint8 i;
560
561 if (feature >= SBP_MAX_MD_FEATURE)
562 {
563 return KAL_FALSE;
564 }
565 else
566 {
567 for (i=0; i<MAX_SIM_NUM; i++)
568 sbp_set_md_feature_by_ps( feature, is_turned_on, i);
569 }
570
571 return KAL_TRUE;
572}
573
574
575
576/*****************************************************************************
577* FUNCTION
578* sbp_query_md_feature_data()
579*
580* DESCRIPTION
581* This function is used to query modem configuration data
582*
583* PARAMETERS
584* feature [IN] modem feature
585*
586* RETURNS
587* the unsigned byte value for the feature
588*****************************************************************************/
589kal_uint8 sbp_query_md_feature_data(sbp_md_feature_data_enum feature)
590{
591
592 return sbp_query_md_feature_data_by_ps(feature, PROTOCOL_1);
593}
594
595#ifdef __CDMA2000_RAT__
596/*****************************************************************************
597* FUNCTION
598* sbp_query_md_feature_data_for_c2k()
599*
600* DESCRIPTION
601* This function is used to query modem configuration and used by C2K team only
602* The function will judge current active PS using C2K's API and return the corresponding setting.
603*
604* PARAMETERS
605* feature [IN] modem feature
606*
607* RETURNS
608* the unsigned byte value for the feature
609*****************************************************************************/
610kal_uint8 sbp_query_md_feature_data_for_c2k(sbp_md_feature_data_enum feature)
611{
612 protocol_id_enum ps_id = ValCurrentActiveSimIndex();
613
614 if (ps_id >= MAX_SIM_NUM)
615 {
616 #ifndef __L1_STANDALONE__
617 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
618 #endif
619
620 return 0;
621 }
622
623 return sbp_query_md_feature_data_by_ps(feature, ps_id);
624}
625#endif
626
627
628/*****************************************************************************
629* FUNCTION
630* sbp_query_md_feature_data_by_ps()
631*
632* DESCRIPTION
633* This function is used to query modem configuration data
634*
635* PARAMETERS
636* feature [IN] modem feature
637* ps_id [IN] PS ID
638*
639* RETURNS
640* the unsigned byte value for the feature
641*****************************************************************************/
642kal_uint8 sbp_query_md_feature_data_by_ps(sbp_md_feature_data_enum feature, protocol_id_enum ps_id)
643{
644 kal_uint8 result;
645#ifndef __L1_STANDALONE__
646 static sbp_md_feature_data_enum latest_queried_sbp[MAX_SIM_NUM];
647#endif
648
649 if (feature >= SBP_DATA_MAX_MD_FEATURE)
650 {
651 DEBUG_ASSERT(0);
652 return 0;
653 }
654 if (ps_id >=MAX_SIM_NUM)
655 {
656#ifndef __L1_STANDALONE__
657 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
658#endif
659 return 0;
660 }
661
662 result = sbp_cntxt_g[ps_id].modem_sbp_data_config[feature];
663
664 //For GCF or other test modes, you may overwrite the result.
665 result = sbp_md_feature_data_overwrite(feature, result);
666
667#ifndef __L1_STANDALONE__
668 if (latest_queried_sbp[ps_id] != feature)
669 {
670 MD_TRC_INFO_SBP_DATA(ps_id, feature, result);
671 latest_queried_sbp[ps_id] = feature;
672 }
673#endif
674
675 return result;
676}
677
678/*****************************************************************************
679* FUNCTION
680* sbp_query_md_feature_data_no_overwrite()
681*
682* DESCRIPTION
683* This function is used to query modem configuration data without overwrite
684*
685* PARAMETERS
686* feature [IN] modem feature
687*
688* RETURNS
689* the unsigned byte value for the feature
690*****************************************************************************/
691kal_uint8 sbp_query_md_feature_data_no_overwrite(sbp_md_feature_data_enum feature)
692{
693 return sbp_query_md_feature_data_no_overwrite_by_ps(feature, PROTOCOL_1);
694}
695
696/*****************************************************************************
697* FUNCTION
698* sbp_query_md_feature_data_no_overwrite_by_ps()
699*
700* DESCRIPTION
701* This function is used to query modem configuration data without overwrite
702*
703* PARAMETERS
704* feature [IN] modem feature
705* ps_id [IN] PS ID
706*
707* RETURNS
708* the unsigned byte value for the feature
709*****************************************************************************/
710kal_uint8 sbp_query_md_feature_data_no_overwrite_by_ps(sbp_md_feature_data_enum feature, protocol_id_enum ps_id)
711{
712 kal_uint8 result;
713#ifndef __L1_STANDALONE__
714 static sbp_md_feature_data_enum latest_queried_sbp[MAX_SIM_NUM];
715#endif
716
717 if (feature >= SBP_DATA_MAX_MD_FEATURE)
718 {
719 DEBUG_ASSERT(0);
720 return 0;
721 }
722 if (ps_id >=MAX_SIM_NUM)
723 {
724#ifndef __L1_STANDALONE__
725 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
726#endif
727 return 0;
728 }
729
730 result = sbp_cntxt_g[ps_id].modem_sbp_data_config[feature];
731
732
733#ifndef __L1_STANDALONE__
734 if (latest_queried_sbp[ps_id] != feature)
735 {
736 MD_TRC_INFO_SBP_DATA(ps_id, feature, result);
737 latest_queried_sbp[ps_id] = feature;
738 }
739#endif
740
741 return result;
742}
743
744
745/*****************************************************************************
746* FUNCTION
747* sbp_set_md_feature_data()
748*
749* DESCRIPTION
750* This function is used to set modem configuration data
751*
752* PARAMETERS
753* feature [IN] modem feature
754*
755* RETURNS
756* the unsigned byte value for the feature
757*****************************************************************************/
758kal_bool sbp_set_md_feature_data(sbp_md_feature_data_enum feature,
759 kal_uint8 data,
760 nvram_ef_sbp_modem_data_config_struct *sbp_data_ptr)
761{
762 if (feature >= SBP_DATA_MAX_MD_FEATURE)
763 {
764 return KAL_FALSE;
765 }
766 else
767 {
768 sbp_data_ptr->modem_sbp_data_config[feature] = data;
769 }
770
771 return KAL_TRUE;
772}
773
774
775/*****************************************************************************
776* FUNCTION
777* sbp_set_md_feature_data_by_ps()
778*
779* DESCRIPTION
780* This function is used to set modem configuration data by PS
781* Please don't use this API if you don't get the permission from SBP FPM.
782*
783* PARAMETERS
784* feature [IN] modem feature
785*
786* RETURNS
787* the unsigned byte value for the feature
788*****************************************************************************/
789kal_bool sbp_set_md_feature_data_by_ps(sbp_md_feature_data_enum feature,
790 kal_uint8 data,
791 protocol_id_enum ps_id)
792{
793 if (feature >= SBP_DATA_MAX_MD_FEATURE)
794 {
795 return KAL_FALSE;
796 }
797 else
798 {
799 sbp_cntxt_g[ps_id].modem_sbp_data_config[feature]= data;
800
801#ifndef __L1_STANDALONE__
802 MD_TRC_INFO_SBP_SET_DATA(ps_id, feature, data);
803#endif
804 }
805
806 return KAL_TRUE;
807}
808
809/*****************************************************************************
810* FUNCTION
811* sbp_general_set_md_feature_data()
812*
813* DESCRIPTION
814* This function is used to set modem configuration data
815* Please don't use this API if you don't get the permission from SBP FPM.
816*
817* PARAMETERS
818* feature [IN] modem feature
819*
820* RETURNS
821* the unsigned byte value for the feature
822*****************************************************************************/
823kal_bool sbp_general_set_md_feature_data(sbp_md_feature_data_enum feature, kal_uint8 data)
824{
825 kal_uint8 i;
826
827 if (feature >= SBP_DATA_MAX_MD_FEATURE)
828 {
829 return KAL_FALSE;
830 }
831 else
832 {
833 for (i=0; i< MAX_SIM_NUM; i++)
834 sbp_set_md_feature_data_by_ps(feature, data, i);
835 }
836
837 return KAL_TRUE;
838}
839
840/*****************************************************************************
841* FUNCTION
842* sbp_query_id()
843*
844* DESCRIPTION
845* This function is used to query SBP ID received by modem
846*
847* PARAMETERS
848* [IN] N/A
849*
850* RETURNS
851* the unsigned 4-byte value for the SBP ID
852*****************************************************************************/
853kal_uint32 sbp_query_id(void)
854{
855 return sbp_common_cntxt_g.sbp_id;
856}
857
858/*****************************************************************************
859* FUNCTION
860* sbp_query_sub_id()
861*
862* DESCRIPTION
863* This function is used to query SBP Sub ID received by modem
864*
865* PARAMETERS
866* [IN] N/A
867* RETURNS
868* the unsigned 4-byte value for the SBP Sub ID
869*****************************************************************************/
870kal_uint32 sbp_query_sub_id(void)
871{
872 return sbp_common_cntxt_g.sbp_sub_id;
873}
874
875/*****************************************************************************
876* FUNCTION
877* sbp_get_sbp_ids_from_cntxt
878*
879* DESCRIPTION
880* This function is used to get NVRAM_EF_SBP_IDS_LID information from current context
881*
882* PARAMETERS
883* param [IN] sbp_ids_ptr
884* RETURNS
885* void
886*
887*****************************************************************************/
888void sbp_get_sbp_ids_from_cntxt(nvram_ef_sbp_ids_struct *sbp_ids_ptr)
889{
890 kal_uint8 i;
891
892 sbp_ids_ptr->sbp_id = sbp_common_cntxt_g.sbp_id;
893 sbp_ids_ptr->test_mode = sbp_common_cntxt_g.test_mode;
894 sbp_ids_ptr->dsbp_mode = sbp_common_cntxt_g.dsbp_mode;
895 for (i=0; i<MAX_SIM_NUM; i++)
896 {
897 sbp_ids_ptr->sim_sbp_id_info[i].sim_sbp_id = sbp_cntxt_g[i].dsbp_sim_sbp_id_mode2;
898 kal_mem_cpy(sbp_ids_ptr->sim_sbp_id_info[i].mcc, sbp_cntxt_g[i].mcc , MAX_MCC_STR_LEN);
899 kal_mem_cpy(sbp_ids_ptr->sim_sbp_id_info[i].mnc, sbp_cntxt_g[i].mnc, MAX_MNC_STR_LEN);
900 kal_mem_cpy(sbp_ids_ptr->sim_sbp_id_info[i].iccid, sbp_cntxt_g[i].iccid, 21);
901 }
902}
903
904/*****************************************************************************
905* FUNCTION
906* sbp_init_contexts()
907*
908* DESCRIPTION
909* This function is used to init SBP Contexts
910*
911* PARAMETERS
912* [IN] N/A
913*
914* RETURNS
915* KAL_TRUE or KAL_FALSE
916*****************************************************************************/
917kal_bool sbp_init_contexts()
918{
919 kal_uint8 i;
920 nvram_ef_sbp_ids_struct sbp_id_buf;
921 nvram_ef_sbp_dsbp_config_struct dsbp_config_buf;
922
923#ifdef __IPC_ADAPTER__
924 nvram_ipc_factory_common_struct ipc_nvram_buf;
925 nvram_ef_sbp_dsbp_info_struct dsbp_info_buf;
926 kal_bool result;
927#endif
928
929 nvram_external_read_data(NVRAM_EF_SBP_DSBP_CONFIG_LID,
930 1,
931 (kal_uint8*)&dsbp_config_buf,
932 NVRAM_EF_SBP_DSBP_CONFIG_SIZE);
933
934 nvram_external_read_data(NVRAM_EF_SBP_IDS_LID,
935 1,
936 (kal_uint8*)&sbp_id_buf,
937 NVRAM_EF_SBP_IDS_SIZE);
938
939 nvram_external_read_data(NVRAM_EF_SBP_CUSTOM_SBP_ID_MAPPING_LID,
940 1,
941 (kal_uint8*)&g_custom_sbp_id_mapping_table,
942 NVRAM_EF_SBP_CUSTOM_SBP_ID_MAPPING_SIZE);
943
944 nvram_external_read_data(NVRAM_EF_SBP_MDCXP_SBP_ID_LIST_LID,
945 1,
946 (kal_uint8*)&g_mdcxp_sbp_id_list,
947 NVRAM_EF_SBP_MDCXP_SBP_ID_LIST_SIZE);
948
949 // prepare SBP Context
950 sbp_common_cntxt_g.sbp_id = sbp_id_buf.sbp_id;
951 sbp_common_cntxt_g.sbp_sub_id= 0;
952 sbp_common_cntxt_g.test_mode = sbp_id_buf.test_mode;
953 sbp_common_cntxt_g.dsbp_mode = sbp_id_buf.dsbp_mode;
954 kal_mem_cpy(&sbp_common_cntxt_g.dsbp_config, &dsbp_config_buf, NVRAM_EF_SBP_DSBP_CONFIG_SIZE);
955
956 for (i=0; i<MAX_SIM_NUM; i++)
957 {
958 sbp_cntxt_g[i].current_sim_sbp_id = SBP_ID_INVALID;
959 sbp_cntxt_g[i].dsbp_sim_sbp_id_mode1 = SBP_ID_INVALID;
960 sbp_cntxt_g[i].dsbp_sim_sbp_id_mode2 = sbp_id_buf.sim_sbp_id_info[i].sim_sbp_id;
961 kal_mem_cpy(sbp_cntxt_g[i].mcc, sbp_id_buf.sim_sbp_id_info[i].mcc, MAX_MCC_STR_LEN);
962 kal_mem_cpy(sbp_cntxt_g[i].mnc, sbp_id_buf.sim_sbp_id_info[i].mnc, MAX_MNC_STR_LEN);
963 kal_mem_cpy(sbp_cntxt_g[i].iccid, sbp_id_buf.sim_sbp_id_info[i].iccid, 21);
964 }
965
966 if (default_sbp_id == SBP_ID_INVALID)
967 default_sbp_id = sbp_id_buf.sbp_id;
968
969#ifdef __IPC_ADAPTER__
970 nvram_external_read_data(NVRAM_EF_IPC_FACTORY_COMMON_LID,
971 1,
972 (kal_uint8*) &ipc_nvram_buf,
973 NVRAM_EF_IPC_FACTORY_COMMON_SIZE);
974
975 memcpy( (void *) sbp_salecode.csc_salecode, (void *) &ipc_nvram_buf.sellout_product_code[11], 3);
976 memcpy( (void *) sbp_salecode.network_code, (void *) ipc_nvram_buf.network_code, 3); // For SIM Slot 0
977 memcpy( (void *) sbp_salecode.network_code_2, (void *) ipc_nvram_buf.network_code_2, 3); // For SIM Slot 1
978
979 result = nvram_external_read_data(NVRAM_EF_SBP_DSBP_INFO_LID,
980 1,
981 (kal_uint8*) &dsbp_info_buf,
982 NVRAM_EF_SBP_DSBP_INFO_SIZE);
983
984 if (result == KAL_TRUE &&
985 dsbp_info_buf.default_dsbp_mode <= 2)
986 {
987 sbp_common_cntxt_g.dsbp_mode = dsbp_info_buf.default_dsbp_mode;
988 }
989#endif
990
991 return KAL_TRUE;
992}
993
994/*****************************************************************************
995* FUNCTION
996* sbp_module_clean
997*
998* DESCRIPTION
999* This function cleans up user sensative informatino for SBP
1000*
1001* PARAMETERS
1002* [IN] N/A
1003* RETURNS
1004* void
1005*
1006*****************************************************************************/
1007void sbp_module_clean(void)
1008{
1009 kal_uint8 i;
1010
1011 for (i=0; i<MAX_SIM_NUM; i++)
1012 {
1013 kal_mem_set(sbp_cntxt_g[i].iccid, 0, 21);
1014 }
1015}
1016
1017/*****************************************************************************
1018* FUNCTION
1019* sbp_set_sbp_id()
1020*
1021* DESCRIPTION
1022* This function is used to set SBP ID into SBP contexts and its NVRAM
1023* Please don't use this API if you don't get the permission from SBP FPM.
1024*
1025* PARAMETERS
1026* [IN] N/A
1027*
1028* RETURNS
1029* KAL_TRUE or KAL_FALSE
1030*****************************************************************************/
1031kal_bool sbp_set_sbp_id(kal_uint32 sbp_id)
1032{
1033 nvram_ef_sbp_ids_struct sbp_id_buf;
1034
1035 sbp_common_cntxt_g.sbp_id = sbp_id;
1036 // Currently, SBP sub ID in the conext will be always the same with default SBP Sub ID form CCCI.
1037 sbp_common_cntxt_g.sbp_sub_id = default_sbp_sub_id;
1038
1039 // fill LID info from current context
1040 sbp_get_sbp_ids_from_cntxt(&sbp_id_buf);
1041
1042 nvram_external_write_data(NVRAM_EF_SBP_IDS_LID,
1043 1,
1044 (kal_uint8*)&sbp_id_buf,
1045 NVRAM_EF_SBP_IDS_SIZE);
1046
1047
1048 return KAL_TRUE;
1049}
1050
1051/*****************************************************************************
1052 * FUNCTION
1053 * sbp_convert_mcc_mnc_string_from_imsi
1054 * DESCRIPTION
1055 * get mcc, mnc from imsi with string format
1056 * PARAMETERS
1057 * imsi
1058 * RETURNS
1059 * KAL_TRUE
1060 *****************************************************************************/
1061kal_bool sbp_convert_mcc_mnc_string_from_imsi(kal_uint8* mcc_ptr, kal_uint32 mcc_size, kal_uint8 *mnc_ptr, kal_uint32 mnc_size, kal_uint8* imsi_ptr, kal_uint8 mnc_len)
1062{
1063 if (!mcc_ptr || !mnc_ptr || !imsi_ptr)
1064 {
1065 return KAL_FALSE;
1066 }
1067
1068 if ((mcc_size < MAX_MCC_STR_LEN) || (mnc_size < MAX_MNC_STR_LEN ))
1069 {
1070 return KAL_FALSE;
1071 }
1072
1073 if ((mnc_len != 2) && (mnc_len != 3))
1074 {
1075 return KAL_FALSE;
1076 }
1077
1078 /* get mcc/mnc and convert to ASCII */
1079 mcc_ptr[0] = (imsi_ptr[0] >> 4) + 48; //mcc1
1080 mcc_ptr[1] = (imsi_ptr[1] & 0x0F) + 48; //mcc2
1081 mcc_ptr[2] = (imsi_ptr[1] >> 4) + 48; //mcc3
1082 mcc_ptr[3] = 0;
1083
1084 mnc_ptr[0] = (imsi_ptr[2] & 0x0F) + 48; //mnc1
1085 mnc_ptr[1] = (imsi_ptr[2] >> 4) + 48; //mnc2
1086 if (mnc_len == 3)
1087 {
1088 mnc_ptr[2] = (imsi_ptr[3] & 0x0F) + 48; //mnc3
1089 }
1090
1091 mnc_ptr[mnc_len] = 0;
1092 mnc_ptr[3] = 0;
1093
1094 return KAL_TRUE;
1095}
1096
1097/*****************************************************************************
1098* FUNCTION
1099* sbp_get_sim_sbp_id_for_all()
1100*
1101* DESCRIPTION
1102* get SIM SBP ID which trigger DSBP for all modem (IMS/VoLTE + PS/L1)
1103*
1104* PARAMETERS
1105* ps_id [IN] protocol ID
1106*
1107* RETURNS
1108* the unsigned 4-byte value for the SIM SBP ID
1109*
1110*****************************************************************************/
1111kal_uint32 sbp_get_sim_sbp_id_for_all(protocol_id_enum ps_id)
1112{
1113 return sbp_cntxt_g[ps_id].dsbp_sim_sbp_id_mode2;
1114}
1115
1116/*****************************************************************************
1117* FUNCTION
1118* sbp_get_current_sim_sbp_id()
1119*
1120* DESCRIPTION
1121* get SIM SBP ID which trigger DSBP for IMS/VoLTE
1122*
1123* PARAMETERS
1124* ps_id [IN] protocol ID
1125*
1126* RETURNS
1127* the unsigned 4-byte value for the SIM SBP ID
1128*
1129*****************************************************************************/
1130kal_uint32 sbp_get_current_sim_sbp_id(protocol_id_enum ps_id)
1131{
1132 return sbp_cntxt_g[ps_id].current_sim_sbp_id;
1133}
1134
1135/*****************************************************************************
1136* FUNCTION
1137* sbp_get_sim_sbp_id()
1138*
1139* DESCRIPTION
1140* get SIM SBP ID which trigger DSBP for IMS/VoLTE
1141*
1142* PARAMETERS
1143* ps_id [IN] protocol ID
1144*
1145* RETURNS
1146* the unsigned 4-byte value for the SIM SBP ID
1147*
1148*****************************************************************************/
1149kal_uint32 sbp_get_sim_sbp_id(protocol_id_enum ps_id)
1150{
1151 return sbp_cntxt_g[ps_id].dsbp_sim_sbp_id_mode1;
1152}
1153
1154/*****************************************************************************
1155* FUNCTION
1156* sbp_set_sim_sbp_id_for_all()
1157*
1158* DESCRIPTION
1159* set SIM SBP ID which trigger DSBP for all modem (IMS/VoLTE + PS/L1)
1160*
1161* PARAMETERS
1162* ps_id [IN] protocol ID
1163* sim_sbp_id [IN] SIM SBP ID
1164* mcc [IN] MCC
1165* mnc [IN] MNC
1166* iccid [IN] ICCID
1167*
1168* RETURNS
1169* KAL_TRUE - success
1170* KAL_FALSE - failure
1171*
1172*****************************************************************************/
1173kal_bool sbp_set_sim_sbp_id_for_all(protocol_id_enum ps_id, kal_uint32 sim_sbp_id, kal_uint8 *mcc, kal_uint8 *mnc, kal_uint8 *iccid)
1174{
1175 nvram_ef_sbp_ids_struct *nvram_ef_sbp_ids_ptr;
1176 kal_bool result = KAL_FALSE;
1177
1178 nvram_ef_sbp_ids_ptr = (nvram_ef_sbp_ids_struct *) get_ctrl_buffer(sizeof(nvram_ef_sbp_ids_struct));
1179
1180 if (nvram_ef_sbp_ids_ptr == NULL)
1181 {
1182 return KAL_FALSE;
1183 }
1184
1185 sbp_cntxt_g[ps_id].dsbp_sim_sbp_id_mode2 = sim_sbp_id;
1186
1187 // read VDM ims_reconfig_enable setting first
1188 /* to use ps_id instead of l4c_gemini_get_actual_sim_id(ps_id),
1189 SIM SBP ID NVRAM LID is combined with protocol stack, not SIM slot
1190 */
1191
1192 // fill LID info from current context
1193 sbp_get_sbp_ids_from_cntxt(nvram_ef_sbp_ids_ptr);
1194
1195 // update LID info with new sim_sbp_id_info
1196 nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].sim_sbp_id = sim_sbp_id;
1197
1198 // For mode2, update both sbp context and NVRAM after DSBP completion
1199 if (mcc == NULL)
1200 {
1201 kal_mem_set(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].mcc, 0, MAX_MCC_STR_LEN);
1202 kal_mem_set(sbp_cntxt_g[ps_id].mcc, 0, MAX_MCC_STR_LEN);
1203 }
1204 else
1205 {
1206 kal_mem_cpy(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].mcc, mcc, MAX_MCC_STR_LEN);
1207 kal_mem_cpy(sbp_cntxt_g[ps_id].mcc, mcc, MAX_MCC_STR_LEN);
1208 }
1209 if (mnc == NULL)
1210 {
1211 kal_mem_set(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].mnc, 0, MAX_MNC_STR_LEN);
1212 kal_mem_set(sbp_cntxt_g[ps_id].mnc, 0, MAX_MNC_STR_LEN);
1213 }
1214 else
1215 {
1216 kal_mem_cpy(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].mnc, mnc, MAX_MNC_STR_LEN);
1217 kal_mem_cpy(sbp_cntxt_g[ps_id].mnc, mnc, MAX_MNC_STR_LEN);
1218 }
1219 if (iccid == NULL)
1220 {
1221 kal_mem_set(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].iccid, 0, 21);
1222 kal_mem_set(sbp_cntxt_g[ps_id].iccid, 0, 21);
1223 }
1224 else
1225 {
1226 kal_mem_cpy(nvram_ef_sbp_ids_ptr->sim_sbp_id_info[ps_id].iccid, iccid, 21);
1227 kal_mem_cpy(sbp_cntxt_g[ps_id].iccid, iccid, 21);
1228 }
1229
1230 result = nvram_external_write_data(NVRAM_EF_SBP_IDS_LID,
1231 1,
1232 (kal_uint8*)nvram_ef_sbp_ids_ptr,
1233 NVRAM_EF_SBP_IDS_SIZE);
1234
1235 // Free allocated buffer
1236 free_ctrl_buffer(nvram_ef_sbp_ids_ptr);
1237
1238 return result;
1239}
1240
1241/*****************************************************************************
1242* FUNCTION
1243* sbp_set_current_sim_sbp_id()
1244*
1245* DESCRIPTION
1246* set SIM SBP ID for current PS
1247*
1248* PARAMETERS
1249* ps_id [IN] protocol ID
1250* sim_sbp_id [IN] SIM SBP ID
1251*
1252* RETURNS
1253* KAL_TRUE - success
1254* KAL_FALSE - failure
1255*
1256*****************************************************************************/
1257kal_bool sbp_set_current_sim_sbp_id(protocol_id_enum ps_id, kal_uint32 sim_sbp_id)
1258{
1259 sbp_cntxt_g[ps_id].current_sim_sbp_id = sim_sbp_id;
1260
1261 return KAL_TRUE;
1262}
1263
1264/*****************************************************************************
1265* FUNCTION
1266* sbp_set_sim_sbp_id()
1267*
1268* DESCRIPTION
1269* set SIM SBP ID which trigger DSBP for IMS/VoLTE
1270*
1271* PARAMETERS
1272* ps_id [IN] protocol ID
1273* sim_sbp_id [IN] SIM SBP ID
1274*
1275* RETURNS
1276* KAL_TRUE - success
1277* KAL_FALSE - failure
1278*
1279*****************************************************************************/
1280kal_bool sbp_set_sim_sbp_id(protocol_id_enum ps_id, kal_uint32 sim_sbp_id, kal_uint8 *mcc, kal_uint8 *mnc, kal_uint8 *iccid)
1281{
1282 // For mode1, update sbp context after DSBP completion
1283 // (but not update NVRAM, mode1 info does not persist after pwr cycle)
1284 sbp_cntxt_g[ps_id].dsbp_sim_sbp_id_mode1 = sim_sbp_id;
1285
1286 if (mcc == NULL)
1287 kal_mem_set(sbp_cntxt_g[ps_id].mcc, 0, MAX_MCC_STR_LEN);
1288 else
1289 kal_mem_cpy(sbp_cntxt_g[ps_id].mcc, mcc, MAX_MCC_STR_LEN);
1290 if (mnc == NULL)
1291 kal_mem_set(sbp_cntxt_g[ps_id].mnc, 0, MAX_MNC_STR_LEN);
1292 else
1293 kal_mem_cpy(sbp_cntxt_g[ps_id].mnc, mnc, MAX_MNC_STR_LEN);
1294 if (iccid == NULL)
1295 kal_mem_set(sbp_cntxt_g[ps_id].iccid, 0, 21);
1296 else
1297 kal_mem_cpy(sbp_cntxt_g[ps_id].iccid, iccid, 21);
1298
1299 return KAL_TRUE;
1300}
1301
1302/*****************************************************************************
1303* FUNCTION
1304* sbp_get_sbp_feature_raw_config()
1305*
1306* DESCRIPTION
1307* Get SBP Feature Raw Data according to the ps_id
1308* Please don't use this API if you don't get the permission from SBP FPM.
1309*
1310* PARAMETERS
1311* ps_id [IN] protocol ID
1312*
1313* RETURNS
1314* KAL_TRUE - success
1315* KAL_FALSE - failure
1316*
1317*****************************************************************************/
1318kal_bool sbp_get_sbp_feature_raw_config(protocol_id_enum ps_id, kal_uint8 *raw_config)
1319{
1320 kal_mem_cpy(raw_config, sbp_cntxt_g[ps_id].modem_sbp_config, (SBP_MAX_MD_FEATURE/8)+1);
1321 return KAL_TRUE;
1322}
1323
1324/*****************************************************************************
1325* FUNCTION
1326* sbp_set_sbp_feature_raw_config()
1327*
1328* DESCRIPTION
1329* Set SBP Feature Raw Data according to the ps_id
1330* Please don't use this API if you don't get the permission from SBP FPM.
1331*
1332* PARAMETERS
1333* ps_id [IN] protocol ID
1334*
1335* RETURNS
1336* KAL_TRUE - success
1337* KAL_FALSE - failure
1338*
1339*****************************************************************************/
1340void sbp_set_sbp_feature_raw_config(protocol_id_enum ps_id, kal_uint8 *raw_config)
1341{
1342 kal_mem_cpy(sbp_cntxt_g[ps_id].modem_sbp_config, raw_config, (SBP_MAX_MD_FEATURE/8)+1);
1343
1344}
1345
1346
1347/*****************************************************************************
1348* FUNCTION
1349* sbp_get_sbp_data_raw_config()
1350*
1351* DESCRIPTION
1352* Get SBP Data Raw Data according to the ps_id
1353* Please don't use this API if you don't get the permission from SBP FPM.
1354*
1355* PARAMETERS
1356* ps_id [IN] protocol ID
1357*
1358* RETURNS
1359* KAL_TRUE - success
1360* KAL_FALSE - failure
1361*
1362*****************************************************************************/
1363kal_bool sbp_get_sbp_data_raw_config(protocol_id_enum ps_id, kal_uint8 *raw_config)
1364{
1365 kal_mem_cpy(raw_config, sbp_cntxt_g[ps_id].modem_sbp_data_config, SBP_DATA_MAX_MD_FEATURE);
1366 return KAL_TRUE;
1367}
1368
1369/*****************************************************************************
1370* FUNCTION
1371* sbp_set_sbp_data_raw_config()
1372*
1373* DESCRIPTION
1374* Get SBP Data Raw Data according to the ps_id
1375* Please don't use this API if you don't get the permission from SBP FPM.
1376*
1377* PARAMETERS
1378* ps_id [IN] protocol ID
1379*
1380* RETURNS
1381* KAL_TRUE - success
1382* KAL_FALSE - failure
1383*
1384*****************************************************************************/
1385void sbp_set_sbp_data_raw_config(protocol_id_enum ps_id, kal_uint8 *raw_config)
1386{
1387 kal_mem_cpy(sbp_cntxt_g[ps_id].modem_sbp_data_config, raw_config, SBP_DATA_MAX_MD_FEATURE);
1388
1389}
1390
1391
1392/*****************************************************************************
1393* FUNCTION
1394* sbp_update_features_to_nvram()
1395*
1396* DESCRIPTION
1397* This function is used to store current config of features from SBP contexts into NVRAM_EF_SBP_MODEM_CONFIG_LID
1398* Please don't use this API if you don't get the permission from SBP FPM.
1399*
1400* PARAMETERS
1401* ps_id [IN] protocol ID
1402*
1403* RETURNS
1404* KAL_TRUE - success
1405* KAL_FALSE - failure
1406*
1407*****************************************************************************/
1408kal_bool sbp_update_features_to_nvram()
1409{
1410 nvram_ef_sbp_modem_config_struct sbp_local_config;
1411
1412 sbp_local_config.sbp_mode = SBP_ID_INVALID;
1413 kal_mem_cpy(sbp_local_config.modem_sbp_config, sbp_cntxt_g[SIM1].modem_sbp_config, (SBP_MAX_MD_FEATURE/8)+1);
1414
1415 nvram_external_write_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
1416 1,
1417 (kal_uint8*)&sbp_local_config,
1418 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
1419
1420 return KAL_TRUE;
1421}
1422
1423/*****************************************************************************
1424* FUNCTION
1425* sbp_update_data_to_nvram()
1426*
1427* DESCRIPTION
1428* This function is used to store current config of data from SBP contexts into NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID
1429* Please don't use this API if you don't get the permission from SBP FPM.
1430*
1431* PARAMETERS
1432* ps_id [IN] protocol ID
1433*
1434* RETURNS
1435* KAL_TRUE - success
1436* KAL_FALSE - failure
1437*
1438*****************************************************************************/
1439kal_bool sbp_update_data_to_nvram()
1440{
1441 nvram_ef_sbp_modem_data_config_struct sbp_local_config;
1442
1443 sbp_local_config.sbp_mode = SBP_ID_INVALID;
1444 kal_mem_cpy(sbp_local_config.modem_sbp_data_config, sbp_cntxt_g[SIM1].modem_sbp_data_config, SBP_DATA_MAX_MD_FEATURE);
1445
1446 nvram_external_write_data(NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID,
1447 1,
1448 (kal_uint8*)&sbp_local_config,
1449 NVRAM_EF_SBP_MODEM_DATA_CONFIG_SIZE);
1450
1451 return KAL_TRUE;
1452}
1453
1454/*****************************************************************************
1455* FUNCTION
1456* sbp_update_specific_feature_to_nvram()
1457*
1458* DESCRIPTION
1459* This function is used to write a single SBP feature to NVRAM, keeping all other features the same
1460*
1461* PARAMETERS
1462* feature [IN] modem feature
1463* is_turned_on [IN]
1464*
1465* RETURNS
1466* KAL_TRUE - success
1467* KAL_FALSE - failure
1468*
1469*****************************************************************************/
1470kal_bool sbp_update_specific_feature_to_nvram(sbp_md_feature_enum feature, kal_bool is_turned_on)
1471{
1472 nvram_ef_sbp_modem_config_struct sbp_local_config;
1473
1474 nvram_external_read_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
1475 1,
1476 (kal_uint8*)&sbp_local_config,
1477 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
1478
1479 sbp_set_md_feature(feature, is_turned_on, (nvram_ef_sbp_modem_config_struct*)&sbp_local_config);
1480
1481 nvram_external_write_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
1482 1,
1483 (kal_uint8*)&sbp_local_config,
1484 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
1485
1486 return KAL_TRUE;
1487}
1488
1489/*****************************************************************************
1490* FUNCTION
1491* sbp_update_specific_data_to_nvram()
1492*
1493* DESCRIPTION
1494* This function is used to write a single SBP feature data to NVRAM, keeping all other feature data the same
1495*
1496* PARAMETERS
1497* feature [IN] modem feature data
1498* data [IN] value of feature data
1499*
1500* RETURNS
1501* KAL_TRUE - success
1502* KAL_FALSE - failure
1503*
1504*****************************************************************************/
1505kal_bool sbp_update_specific_data_to_nvram(sbp_md_feature_data_enum feature, kal_uint8 data)
1506{
1507 nvram_ef_sbp_modem_data_config_struct sbp_local_config;
1508
1509 nvram_external_read_data(NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID,
1510 1,
1511 (kal_uint8*)&sbp_local_config,
1512 NVRAM_EF_SBP_MODEM_DATA_CONFIG_SIZE);
1513
1514 sbp_set_md_feature_data(feature, data, (nvram_ef_sbp_modem_data_config_struct*)&sbp_local_config);
1515
1516 nvram_external_write_data(NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID,
1517 1,
1518 (kal_uint8*)&sbp_local_config,
1519 NVRAM_EF_SBP_MODEM_DATA_CONFIG_SIZE);
1520
1521 return KAL_TRUE;
1522}
1523
1524/*****************************************************************************
1525* FUNCTION
1526* sbp_reload_config()
1527*
1528* DESCRIPTION
1529* This function is used to reload SBP related feature/data configuration
1530* Please don't use this API if you don't get the permission from SBP FPM.
1531*
1532* PARAMETERS
1533* ps_id [IN] protocol ID
1534*
1535* RETURNS
1536* KAL_TRUE - success
1537* KAL_FALSE - failure
1538*
1539*****************************************************************************/
1540void sbp_reload_config()
1541{
1542 kal_bool result;
1543 kal_uint8 i;
1544 nvram_ef_sbp_modem_config_struct sbp_feature_buf;
1545 nvram_ef_sbp_modem_data_config_struct sbp_data_buf;
1546#if defined (__TC01_NVRAM__) || defined(__TC01__) // __TC01_CUST_SBP__
1547 nvram_ef_sbp_modem_config_struct sbp_cust_feature_buf;
1548#endif
1549
1550 /* load SBP file */
1551 result = nvram_external_read_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
1552 1,
1553 (kal_uint8*)&sbp_feature_buf,
1554 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
1555 if (result == KAL_TRUE)
1556 {
1557 for (i=0; i<MAX_SIM_NUM; i++)
1558 {
1559 kal_mem_cpy(&sbp_cntxt_g[i].modem_sbp_config, sbp_feature_buf.modem_sbp_config, (SBP_MAX_MD_FEATURE/8)+1);
1560 }
1561 }
1562 else
1563 {
1564 kal_sys_trace("Reload SBP features settings from NVRAM fail");
1565 }
1566
1567
1568 result = nvram_external_read_data(NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID,
1569 1,
1570 (kal_uint8*)&sbp_data_buf,
1571 NVRAM_EF_SBP_MODEM_DATA_CONFIG_SIZE);
1572
1573 if (result == KAL_TRUE)
1574 {
1575 for (i=0; i<MAX_SIM_NUM; i++)
1576 {
1577 kal_mem_cpy(&sbp_cntxt_g[i].modem_sbp_data_config, sbp_data_buf.modem_sbp_data_config, SBP_DATA_MAX_MD_FEATURE);
1578 }
1579 }
1580 else
1581 {
1582 kal_sys_trace("Reload SBP data settings from NVRAM fail");
1583 }
1584
1585#if defined (__TC01_NVRAM__) || defined(__TC01__) // __TC01_CUST_SBP__
1586 result = nvram_external_read_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
1587 NVRAM_CUST_SBP_IDX,
1588 (kal_uint8*)&sbp_cust_feature_buf,
1589 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
1590 if (result == KAL_TRUE)
1591 {
1592 for (i=0; i<MAX_SIM_NUM; i++)
1593 {
1594 kal_mem_cpy(&sbp_cntxt_g[i].modem_cust_sbp_config, sbp_cust_feature_buf.modem_sbp_config, (SBP_CUSTOM_MAX_MD_FEATURE/8)+1);
1595 }
1596 }
1597 else
1598 {
1599 kal_sys_trace("Reload Custom SBP features settings from NVRAM fail");
1600 }
1601#endif
1602
1603}
1604
1605
1606/*****************************************************************************
1607* FUNCTION
1608* sbp_get_reconfig_param()
1609*
1610* DESCRIPTION
1611* This function is used to get MCC/MNC/ICCID information, which is used to compute SIM SBP ID
1612* from SBP contexts
1613* Please don't use this API if there is no permission from SBP FW owner
1614*
1615* PARAMETERS
1616* ps_id [IN] protocol ID
1617* param [IN] sbp_reconfig_custom_param_struct
1618* RETURNS
1619* void
1620*
1621*****************************************************************************/
1622void sbp_get_reconfig_param(protocol_id_enum ps_id, sbp_reconfig_custom_param_struct *param)
1623{
1624 kal_mem_cpy(param->mcc, sbp_cntxt_g[ps_id].mcc, MAX_MCC_STR_LEN);
1625 kal_mem_cpy(param->mnc, sbp_cntxt_g[ps_id].mnc, MAX_MNC_STR_LEN);
1626 kal_mem_cpy(param->iccid, sbp_cntxt_g[ps_id].iccid, 21);
1627}
1628
1629/*****************************************************************************
1630* FUNCTION
1631* sbp_get_last_dsbp_sim_info()
1632*
1633* DESCRIPTION
1634* This function is used to get MCC/MNC/ICCID of last completed DSBP
1635* For mode2 device, this will include SIM info from last power up
1636* For mode1 device, only include SIM info in current sbp context
1637*
1638* PARAMETERS
1639* ps_id [IN] protocol ID
1640* param [IN] mcc, mnc, iccid
1641* RETURNS
1642* void
1643*
1644*****************************************************************************/
1645void sbp_get_last_dsbp_sim_info(protocol_id_enum ps_id, kal_uint8 *mcc, kal_uint8 *mnc, kal_uint8 *iccid)
1646{
1647 kal_mem_cpy(mcc, sbp_cntxt_g[ps_id].mcc, MAX_MCC_STR_LEN);
1648 kal_mem_cpy(mnc, sbp_cntxt_g[ps_id].mnc, MAX_MNC_STR_LEN);
1649 kal_mem_cpy(iccid, sbp_cntxt_g[ps_id].iccid, 21);
1650
1651 MD_TRC_INFO_SBP_LAST_DSBP_SIM_INFO(ps_id, sbp_cntxt_g[ps_id].mcc, sbp_cntxt_g[ps_id].mnc);
1652}
1653
1654/*****************************************************************************
1655* FUNCTION
1656* sbp_get_last_mode2_dsbp_sim_info()
1657*
1658* DESCRIPTION
1659* This function is used to get SIM_SBP_ID/MCC/MNC/ICCID of last completed mode2 DSBP
1660* Can be used in DSBP callback function to compare with last mode2 DSBP result
1661* As part of mode2 design, this includes info from SIM insert of last power cycle
1662*
1663* PARAMETERS
1664* ps_id [IN] protocol ID
1665* param [IN] sim_sbp_id, mcc, mnc, iccid
1666* RETURNS
1667* void
1668*
1669*****************************************************************************/
1670void sbp_get_last_mode2_dsbp_sim_info(protocol_id_enum ps_id, kal_uint32 *sim_sbp_id, kal_uint8 *mcc, kal_uint8 *mnc, kal_uint8 *iccid)
1671{
1672 *sim_sbp_id = sbp_cntxt_g[ps_id].dsbp_sim_sbp_id_mode2;
1673 kal_mem_cpy(mcc, sbp_cntxt_g[ps_id].mcc, MAX_MCC_STR_LEN);
1674 kal_mem_cpy(mnc, sbp_cntxt_g[ps_id].mnc, MAX_MNC_STR_LEN);
1675 kal_mem_cpy(iccid, sbp_cntxt_g[ps_id].iccid, 21);
1676}
1677
1678/*****************************************************************************
1679* FUNCTION
1680* sbp_update_custom_config_to_nvram
1681*
1682* DESCRIPTION
1683* This function updates sbp feature/data custom config to nvram
1684*
1685* PARAMETERS
1686* ps_id [IN] protocol ID
1687* is_erase [IN] reset the feature/data item or not
1688* RETURNS
1689* void
1690*
1691*****************************************************************************/
1692kal_bool sbp_update_custom_config_to_nvram(sbp_custom_config_struct *sbp_custom_config_ptr, kal_bool is_erase)
1693{
1694 kal_bool result = KAL_FALSE;
1695 nvram_ef_sbp_custom_modem_config_struct *sbp_custom_modem_config_nv_ptr;
1696 sbp_custom_config_struct *sbp_custom_config_nv_ptr;
1697 kal_uint32 i = 0;
1698
1699 sbp_custom_modem_config_nv_ptr = (nvram_ef_sbp_custom_modem_config_struct *) get_ctrl_buffer(
1700 sizeof(nvram_ef_sbp_custom_modem_config_struct));
1701
1702 if (sbp_custom_modem_config_nv_ptr == NULL)
1703 {
1704 return KAL_FALSE;
1705 }
1706
1707 result = nvram_external_read_data(NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_LID,
1708 1,
1709 (kal_uint8*)sbp_custom_modem_config_nv_ptr,
1710 NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_SIZE);
1711
1712 if (result == KAL_TRUE)
1713 {
1714 // Erase any duplicate entry
1715 for (i = 0; i < SBP_MAX_CUSTOM_CONFIG; i++)
1716 {
1717 sbp_custom_config_nv_ptr = &sbp_custom_modem_config_nv_ptr->sbp_custom_config[i];
1718 if (sbp_custom_config_nv_ptr->sbp_id == sbp_custom_config_ptr->sbp_id &&
1719 sbp_custom_config_nv_ptr->sbp_cust_cfg_type == sbp_custom_config_ptr->sbp_cust_cfg_type &&
1720 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature == sbp_custom_config_ptr->sbp_cust_cfg_feature)
1721 {
1722 sbp_custom_config_nv_ptr->sbp_id = 0;
1723 sbp_custom_config_nv_ptr->sbp_cust_cfg_type = 0;
1724 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature = 0;
1725 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature_val = 0;
1726 }
1727 }
1728
1729 // For update, find empty index so we can update to nvram
1730 if (is_erase == KAL_FALSE)
1731 {
1732 for (i = 0; i < SBP_MAX_CUSTOM_CONFIG; i++)
1733 {
1734 sbp_custom_config_nv_ptr = &sbp_custom_modem_config_nv_ptr->sbp_custom_config[i];
1735
1736 if (sbp_custom_config_nv_ptr->sbp_id == 0 &&
1737 sbp_custom_config_nv_ptr->sbp_cust_cfg_type == 0 &&
1738 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature == 0 &&
1739 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature_val == 0)
1740 {
1741 sbp_custom_config_nv_ptr->sbp_id = sbp_custom_config_ptr->sbp_id;
1742 sbp_custom_config_nv_ptr->sbp_cust_cfg_type = sbp_custom_config_ptr->sbp_cust_cfg_type;
1743 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature = sbp_custom_config_ptr->sbp_cust_cfg_feature;
1744 sbp_custom_config_nv_ptr->sbp_cust_cfg_feature_val = sbp_custom_config_ptr->sbp_cust_cfg_feature_val;
1745 break;
1746 }
1747 }
1748 // all indices are not empty, update fail
1749 if (i == SBP_MAX_CUSTOM_CONFIG)
1750 {
1751 MD_TRC_INFO_SBP_UPDATE_NVRAM_NO_EMPTY_FAIL();
1752 result = KAL_FALSE;
1753 }
1754 }
1755
1756 if (result == KAL_TRUE)
1757 {
1758 nvram_external_write_data(NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_LID,
1759 1,
1760 (kal_uint8*)sbp_custom_modem_config_nv_ptr,
1761 NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_SIZE);
1762 }
1763 }
1764 else
1765 {
1766 MD_TRC_INFO_SBP_UPDATE_NVRAM_ACCESS_FAIL();
1767 }
1768
1769 // Free allocated buffer
1770 free_ctrl_buffer(sbp_custom_modem_config_nv_ptr);
1771
1772 return result;
1773}
1774
1775/*****************************************************************************
1776* FUNCTION
1777* sbp_get_custom_config_nv_with_mcf
1778*
1779* DESCRIPTION
1780* This function reads NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_LID and applies MCF OTA by OP change
1781* This funciton uses latest DSBP SIM info and shall not be used during DSBP
1782*
1783* PARAMETERS
1784* ps_id [IN] protocol ID
1785*
1786* RETURNS
1787* void
1788*
1789*****************************************************************************/
1790kal_bool sbp_get_custom_config_nv_with_mcf(protocol_id_enum ps_id, nvram_ef_sbp_custom_modem_config_struct * sbp_custom_modem_config_nv_ptr)
1791{
1792 mcf_tlvota_sbp_tag_t sbp_tag;
1793 kal_bool result = KAL_FALSE;
1794
1795 result = nvram_external_read_data(NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_LID,
1796 1,
1797 (kal_uint8*)sbp_custom_modem_config_nv_ptr,
1798 NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_SIZE);
1799
1800 if (result == KAL_TRUE)
1801 {
1802 // get SBP tag from latest mode2 info
1803 memset(&sbp_tag.mcc,'\0',sizeof(kal_uint8)*MAX_MCC_STR_LEN);
1804 memset(&sbp_tag.mnc,'\0',sizeof(kal_uint8)*MAX_MNC_STR_LEN);
1805
1806 sbp_tag.sbp_id = sbp_get_sim_sbp_id_for_all(ps_id); // MCF OTA by OP uses mode2 DSBP
1807 memcpy(&sbp_tag.mcc, &sbp_cntxt_g[ps_id].mcc, sizeof(kal_uint8)*MAX_MCC_STR_LEN);
1808 memcpy(&sbp_tag.mnc, &sbp_cntxt_g[ps_id].mnc, sizeof(kal_uint8)*MAX_MNC_STR_LEN);
1809
1810 mcf_read_tlvota_buffer_sbp_tag(ps_id, sbp_tag, NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_LID,
1811 (kal_uint8 *)sbp_custom_modem_config_nv_ptr, NVRAM_EF_SBP_CUSTOM_MODEM_CONFIG_SIZE);
1812 }
1813
1814 return result;
1815}
1816
1817/*****************************************************************************
1818* FUNCTION
1819* sbp_get_max_custom_config
1820*
1821* DESCRIPTION
1822* This function gets MAX custom config NV entries
1823*
1824* PARAMETERS
1825* [IN] N/A
1826* RETURNS
1827* void
1828*
1829*****************************************************************************/
1830kal_uint16 sbp_get_max_custom_config(void)
1831{
1832 return SBP_MAX_CUSTOM_CONFIG;
1833}
1834
1835/*****************************************************************************
1836* FUNCTION
1837* sbp_get_dsbp_config
1838*
1839* DESCRIPTION
1840* This function is used to get dsbp config
1841*
1842* PARAMETERS
1843* void
1844* RETURNS
1845* nvram_ef_sbp_dsbp_config_struct
1846*
1847*****************************************************************************/
1848nvram_ef_sbp_dsbp_config_struct* sbp_get_dsbp_config()
1849{
1850 return &sbp_common_cntxt_g.dsbp_config;
1851}
1852
1853/*****************************************************************************
1854* FUNCTION
1855* nvram_custom_config_refresh_sbp_id_mapping_when_mcf_ota_start
1856*
1857* DESCRIPTION
1858* This function is used to re-read NVRAM and update the globle custom sbp_id mapping table
1859* when MCF default OTA triggered.
1860*
1861* PARAMETERS
1862* [IN] N/A
1863* RETURNS
1864* void
1865*
1866*****************************************************************************/
1867void nvram_custom_config_refresh_sbp_id_mapping_when_mcf_ota_start(void)
1868{
1869 nvram_external_read_data(NVRAM_EF_SBP_CUSTOM_SBP_ID_MAPPING_LID,
1870 1,
1871 (kal_uint8*)&g_custom_sbp_id_mapping_table,
1872 NVRAM_EF_SBP_CUSTOM_SBP_ID_MAPPING_SIZE);
1873
1874 nvram_external_read_data(NVRAM_EF_SBP_MDCXP_SBP_ID_LIST_LID,
1875 1,
1876 (kal_uint8*)&g_mdcxp_sbp_id_list,
1877 NVRAM_EF_SBP_MDCXP_SBP_ID_LIST_SIZE);
1878}
1879
1880/*****************************************************************************
1881* FUNCTION
1882* sbp_get_md_cxp_sbp_id
1883*
1884* DESCRIPTION
1885* This function is used to get trigger modem CXP (device) sbp_id
1886*
1887* PARAMETERS
1888* kal_uint32 sim_sbp_id
1889* RETURNS
1890* kal_uint32 md_cxp_sbp_id
1891*
1892*****************************************************************************/
1893kal_uint32 sbp_get_md_cxp_sbp_id(kal_uint32 sim_sbp_id)
1894{
1895 kal_uint8 i;
1896
1897 for (i=0; i < SBP_MAX_MDCXP_SBP_ID_NUM; i++)
1898 {
1899 if (g_mdcxp_sbp_id_list.sbp_id_list[i] == sim_sbp_id)
1900 {
1901 // sim_sbp_id found in list
1902 return sim_sbp_id;
1903 }
1904 }
1905 // sim_sbp_id not found in list, treat as OM
1906 return 0;
1907}
1908
1909/*****************************************************************************
1910* FUNCTION
1911* sbp_set_md_cxp_sbp_id
1912*
1913* DESCRIPTION
1914* This function is used to add trigger modem CXP (device) sbp_id
1915*
1916* PARAMETERS
1917* kal_uint32 sbp_id
1918* RETURNS
1919*
1920*****************************************************************************/
1921void sbp_set_md_cxp_sbp_id(kal_uint32 sbp_id)
1922{
1923 kal_uint8 i;
1924
1925 for (i=0; i < SBP_MAX_MDCXP_SBP_ID_NUM; i++)
1926 {
1927 if (g_mdcxp_sbp_id_list.sbp_id_list[i] == 0)
1928 {
1929 g_mdcxp_sbp_id_list.sbp_id_list[i] = sbp_id;
1930 return ;
1931 }
1932 }
1933 return ;
1934}
1935
1936/*****************************************************************************
1937* FUNCTION
1938* sbp_get_custom_sbp_id_mapping_table
1939*
1940* DESCRIPTION
1941* This function is used to get the globle custom sbp_id mapping table
1942*
1943* PARAMETERS
1944* void
1945* RETURNS
1946* nvram_ef_sbp_custom_sbp_id_mapping_struct
1947*
1948*****************************************************************************/
1949nvram_ef_sbp_custom_sbp_id_mapping_struct* sbp_get_custom_sbp_id_mapping_table(void)
1950{
1951 return &g_custom_sbp_id_mapping_table;
1952}
1953
1954#if defined (__TC01_NVRAM__) || defined(__TC01__) // __TC01_CUST_SBP__
1955/*****************************************************************************
1956* FUNCTION
1957* sbp_query_md_feature_custom()
1958*
1959* DESCRIPTION
1960* clone sbp_query_md_feature() for customer's SBP.
1961*
1962* PARAMETERS
1963* feature [IN] customer's modem feature
1964*
1965* RETURNS
1966* KAL_TRUE : if this feature is turned on
1967* KAL_FALSE : if this feature is turned off
1968*****************************************************************************/
1969kal_bool sbp_query_md_feature_custom(sbp_md_feature_custom_enum feature)
1970{
1971 return sbp_query_md_feature_by_ps_custom(feature, PROTOCOL_1);
1972}
1973
1974/*****************************************************************************
1975* FUNCTION
1976* sbp_query_md_feature_by_ps_custom()
1977*
1978* DESCRIPTION
1979* clone sbp_query_md_feature_by_ps() for customer's SBP.
1980*
1981* PARAMETERS
1982* feature [IN] customer's modem feature
1983* ps_id [IN] PS ID
1984*
1985* RETURNS
1986* KAL_TRUE : if this feature is turned on
1987* KAL_FALSE : if this feature is turned off
1988*****************************************************************************/
1989kal_bool sbp_query_md_feature_by_ps_custom(sbp_md_feature_custom_enum feature, protocol_id_enum ps_id)
1990{
1991 kal_uint8 *bitmask_ptr;
1992 kal_uint32 byte_offset;
1993 kal_uint8 bit_offset;
1994 kal_bool result;
1995
1996#ifndef __L1_STANDALONE__
1997 static sbp_md_feature_custom_enum latest_queried_sbp[MAX_SIM_NUM];
1998#endif
1999
2000 if (feature >= SBP_CUSTOM_MAX_MD_FEATURE)
2001 {
2002 ASSERT(0);
2003 }
2004 if (ps_id >=MAX_SIM_NUM)
2005 {
2006#ifndef __L1_STANDALONE__
2007 MD_TRC_ERROR_SBP_INVALID_PS_ID(ps_id);
2008#endif
2009 return KAL_FALSE;
2010 }
2011
2012 byte_offset = feature / 8;
2013 bit_offset = feature % 8;
2014 bitmask_ptr = &(sbp_cntxt_g[ps_id].modem_cust_sbp_config[byte_offset]);
2015
2016 result = (((*bitmask_ptr) & (0x01 << bit_offset)) != 0)? KAL_TRUE : KAL_FALSE;
2017
2018#ifndef __L1_STANDALONE__
2019 if (latest_queried_sbp[ps_id] != feature)
2020 {
2021// kal_brief_trace(TRACE_GROUP_1, INFO_CUSTOM_SBP_FEATURE, ps_id, feature, result);
2022 latest_queried_sbp[ps_id] = feature;
2023 }
2024#endif
2025
2026 return result;
2027}
2028
2029
2030/*****************************************************************************
2031* FUNCTION
2032* sbp_set_md_feature_custom()
2033*
2034* DESCRIPTION
2035* clone sbp_set_md_feature() for customer's SBP.
2036*
2037* PARAMETERS
2038* feature [IN] customer's modem feature
2039* is_turned_on [IN]
2040* sbp_feature_ptr [IN/OUT]
2041*
2042* RETURNS
2043* KAL_TRUE if success; otherwise KAL_FALSE
2044*****************************************************************************/
2045kal_bool sbp_set_md_feature_custom(sbp_md_feature_custom_enum feature,
2046 kal_bool is_turned_on,
2047 nvram_ef_sbp_modem_config_struct *sbp_feature_ptr)
2048{
2049 kal_uint8 *bitmask_ptr;
2050 kal_uint32 byte_offset;
2051 kal_uint8 bit_offset;
2052
2053
2054 if (feature >= SBP_CUSTOM_MAX_MD_FEATURE)
2055 {
2056 return KAL_FALSE;
2057 }
2058 else
2059 {
2060 byte_offset = feature / 8;
2061 bit_offset = feature % 8;
2062 bitmask_ptr = &(sbp_feature_ptr->modem_sbp_config[byte_offset]);
2063 if (is_turned_on == KAL_TRUE)
2064 {
2065 *bitmask_ptr = ((*bitmask_ptr) | (0x01 << bit_offset));
2066 }
2067 else
2068 {
2069 *bitmask_ptr = ((*bitmask_ptr) & ~(0x01 << bit_offset));
2070 }
2071 }
2072
2073 return KAL_TRUE;
2074}
2075
2076/*****************************************************************************
2077* FUNCTION
2078* sbp_set_md_feature_by_ps_custom()
2079*
2080* DESCRIPTION
2081* clone sbp_set_md_feature_by_ps() for customer's SBP.
2082*
2083* PARAMETERS
2084* feature [IN] customer's modem feature
2085* is_turned_on [IN]
2086* sbp_feature_ptr [IN/OUT]
2087*
2088* RETURNS
2089* KAL_TRUE if success; otherwise KAL_FALSE
2090*****************************************************************************/
2091kal_bool sbp_set_md_feature_by_ps_custom(sbp_md_feature_custom_enum feature,
2092 kal_bool is_turned_on,
2093 protocol_id_enum ps_id)
2094{
2095 kal_uint8 *bitmask_ptr;
2096 kal_uint32 byte_offset;
2097 kal_uint8 bit_offset;
2098
2099 if (feature >= SBP_CUSTOM_MAX_MD_FEATURE)
2100 {
2101 return KAL_FALSE;
2102 }
2103 else
2104 {
2105 byte_offset = feature / 8;
2106 bit_offset = feature % 8;
2107 bitmask_ptr = &(sbp_cntxt_g[ps_id].modem_cust_sbp_config[byte_offset]);
2108 if (is_turned_on == KAL_TRUE)
2109 {
2110 *bitmask_ptr = ((*bitmask_ptr) | (0x01 << bit_offset));
2111 }
2112 else
2113 {
2114 *bitmask_ptr = ((*bitmask_ptr) & ~(0x01 << bit_offset));
2115 }
2116
2117#ifndef __L1_STANDALONE__
2118// kal_brief_trace(TRACE_INFO, INFO_CUSTOM_SBP_SET_FEATURE, ps_id, feature, is_turned_on);
2119#endif
2120 }
2121
2122 return KAL_TRUE;
2123}
2124
2125/*****************************************************************************
2126* FUNCTION
2127* sbp_general_set_md_feature_custom()
2128*
2129* DESCRIPTION
2130* clone sbp_general_set_md_feature() for customer's SBP.
2131*
2132* PARAMETERS
2133* feature [IN] customer's modem feature
2134* is_turned_on [IN]
2135*
2136* RETURNS
2137* KAL_TRUE if success; otherwise KAL_FALSE
2138*****************************************************************************/
2139kal_bool sbp_general_set_md_feature_custom(sbp_md_feature_custom_enum feature, kal_bool is_turned_on)
2140{
2141 kal_uint8 i;
2142
2143 if (feature >= SBP_CUSTOM_MAX_MD_FEATURE)
2144 {
2145 return KAL_FALSE;
2146 }
2147 else
2148 {
2149 for (i=0; i<MAX_SIM_NUM; i++)
2150 sbp_set_md_feature_by_ps_custom( feature, is_turned_on, i);
2151 }
2152
2153 return KAL_TRUE;
2154}
2155
2156/*****************************************************************************
2157* FUNCTION
2158* sbp_update_features_to_nvram_custom()
2159*
2160* DESCRIPTION
2161* clone sbp_update_features_to_nvram() for customer's SBP.
2162*
2163* PARAMETERS
2164* ps_id [IN] protocol ID
2165*
2166* RETURNS
2167* KAL_TRUE - success
2168* KAL_FALSE - failure
2169*
2170*****************************************************************************/
2171kal_bool sbp_update_features_to_nvram_custom()
2172{
2173 nvram_ef_sbp_modem_config_struct sbp_local_config;
2174
2175 sbp_local_config.sbp_mode = SBP_ID_INVALID;
2176 kal_mem_cpy(sbp_local_config.modem_sbp_config, sbp_cntxt_g[SIM1].modem_cust_sbp_config, (SBP_CUSTOM_MAX_MD_FEATURE/8)+1);
2177
2178 nvram_external_write_data(NVRAM_EF_SBP_MODEM_CONFIG_LID,
2179 NVRAM_CUST_SBP_IDX,
2180 (kal_uint8*)&sbp_local_config,
2181 NVRAM_EF_SBP_MODEM_CONFIG_SIZE);
2182
2183 return KAL_TRUE;
2184}
2185
2186
2187/*****************************************************************************
2188 * FUNCTION
2189* sbp_get_sbp_feature_raw_config_custom()
2190*
2191* DESCRIPTION
2192* clone sbp_get_sbp_feature_raw_config() for customer's SBP.
2193*
2194* PARAMETERS
2195* ps_id [IN] protocol ID
2196*
2197* RETURNS
2198* KAL_TRUE - success
2199* KAL_FALSE - failure
2200*
2201*****************************************************************************/
2202kal_bool sbp_get_sbp_feature_raw_config_custom(protocol_id_enum ps_id, kal_uint8 *raw_config)
2203{
2204 kal_mem_cpy(raw_config, sbp_cntxt_g[ps_id].modem_cust_sbp_config, (SBP_CUSTOM_MAX_MD_FEATURE/8)+1);
2205 return KAL_TRUE;
2206}
2207
2208/*****************************************************************************
2209* FUNCTION
2210* sbp_set_sbp_feature_raw_config_custom()
2211*
2212* DESCRIPTION
2213* clone sbp_set_sbp_feature_raw_config() for customer's SBP.
2214*
2215* PARAMETERS
2216* ps_id [IN] protocol ID
2217*
2218* RETURNS
2219* KAL_TRUE - success
2220* KAL_FALSE - failure
2221*
2222*****************************************************************************/
2223void sbp_set_sbp_feature_raw_config_custom(protocol_id_enum ps_id, kal_uint8 *raw_config)
2224{
2225 kal_mem_cpy(sbp_cntxt_g[ps_id].modem_cust_sbp_config, raw_config, (SBP_CUSTOM_MAX_MD_FEATURE/8)+1);
2226
2227}
2228
2229#endif /* (__TC01_NVRAM__) || defined(__TC01__)*/
2230
2231#ifdef __IPC_ADAPTER__
2232/*****************************************************************************
2233* FUNCTION
2234* sbp_get_salecode()
2235*
2236* DESCRIPTION
2237* This function is used to get salecode of this ps_id
2238* If network code is present, network code is given
2239* otherwise, csc_salecode is given
2240*
2241* PARAMETERS
2242* ps_id [IN] protocol ID
2243* param [IN] salecode
2244* RETURNS
2245* void
2246*
2247*****************************************************************************/
2248void sbp_get_salecode(kal_char *salecode, protocol_id_enum ps_id)
2249{
2250 kal_uint8 sim_id;
2251 sim_id = l4c_gemini_get_actual_sim_id(ps_id);
2252
2253 if (sim_id == SIM1)
2254 {
2255 if (sbp_salecode.network_code[0] == 0 && sbp_salecode.network_code[1] == 0 && sbp_salecode.network_code[2] == 0)
2256 {
2257 memcpy( (void *) salecode, (void *) sbp_salecode.csc_salecode, 3);
2258 }
2259 else
2260 {
2261 memcpy( (void *) salecode, (void *) sbp_salecode.network_code, 3);
2262 }
2263 }
2264 else if (sim_id == SIM2)
2265 {
2266 if (sbp_salecode.network_code_2[0] == 0 && sbp_salecode.network_code_2[1] == 0 && sbp_salecode.network_code_2[2] == 0)
2267 {
2268 memcpy( (void *) salecode, (void *) sbp_salecode.csc_salecode, 3);
2269 }
2270 else
2271 {
2272 memcpy( (void *) salecode, (void *) sbp_salecode.network_code_2, 3);
2273 }
2274 }
2275}
2276
2277void sbp_get_csc_salecode(kal_char *salecode)
2278{
2279 memcpy( (void *) salecode, (void *) sbp_salecode.csc_salecode, 3);
2280}
2281
2282void sbp_get_network_code_salecode(kal_char *salecode, protocol_id_enum ps_id)
2283{
2284 kal_uint8 sim_id;
2285 sim_id = l4c_gemini_get_actual_sim_id(ps_id);
2286
2287 if (sim_id == SIM1)
2288 {
2289 memcpy( (void *) salecode, (void *) sbp_salecode.network_code, 3);
2290 }
2291 else if (sim_id == SIM2)
2292 {
2293 memcpy( (void *) salecode, (void *) sbp_salecode.network_code_2, 3);
2294 }
2295}
2296#endif /* __IPC_ADAPTER__ */
2297