mirror from https://www.codeaurora.org/git/projects/hisense-ts7008/repository/
[huawei.git] / AMSS / nv / nvim.c
1 /*===========================================================================\r
2 \r
3                    N V   I T E M    M A N A G E R  T A S K\r
4 DESCRIPTION\r
5   All the declarations and definitions necessary to support the table  \r
6   lookup of mapping between an NV item and the Flash File System files\r
7   which simulate storage in an EEPROM.  External tasks queue requests for\r
8   this task for NV EEPROM read and write operations.  This tasks then \r
9   performs the necessary internal operations to read, write\r
10   and control access to the Flash File System files which simulate storage\r
11   in an EEPROM.   \r
12   This task includes the following files:\r
13     nv.h                   -  NVM Item Manager task services\r
14     nvim.h,     nvim.c     -  NVM Item Manager item services\r
15     nvio.h,     nvio.c     -  NVM Item Manager read/write services\r
16     nvi.h                  -  Common definitions\r
17 \r
18 EXTERNALIZED FUNCTIONS\r
19     nv_write_err_log\r
20       Write an error log without requiring any tasking services.\r
21     nv_read_err_log\r
22       Read an error log without requiring any tasking services.\r
23     nv_cmd\r
24       This is the applications read and write interface to this task.\r
25     nv_task\r
26       This is the nv task initialization entry, started up with rex_def_task.\r
27     \r
28 INITIALIZATION AND SEQUENCING REQUIREMENTS\r
29   This task should be started up with rex_def_task.  Caution must be\r
30   taken when invoking error services from this task.  These services invoke\r
31   this task again (to log errors) and could cause an infinite loop.\r
32   \r
33 \r
34 Copyright (c) 2005-2010 by QUALCOMM, Incorporated.\r
35 All Rights Reserved.\r
36 Qualcomm Confidential and Proprietary\r
37 \r
38 ===========================================================================*/\r
39 \r
40 \r
41 /*===========================================================================\r
42 \r
43                            EDIT HISTORY FOR FILE\r
44 \r
45 $Header: //source/qcom/qct/core/pkg/2H09/halcyon_modem/rel/LA2.0/AMSS/products/7x30/core/services/nv/src/nvim.c#1 $ $DateTime: 2010/10/20 22:41:15 $ $Author: cbirch $\r
46    \r
47 when       who     what, where, why\r
48 --------   ---     ---------------------------------------------------------\r
49 10/12/09   as      Moved nvdiag_init call in to NVIM task \r
50 09/25/09   pc      Dual SIM/Dual Standby support for LCU\r
51 07/23/09   sri     UMTS build support for remoted functions: nv_rtre_control,\r
52                    nv_rtre_polling_for_nam and nv_rtre_polling_control\r
53 07/08/09   sri     Moved function implementations from nv.h and removed inline\r
54 05/27/09   sri     Adding "default" case in nvim_remove_item and the function\r
55                    nv_cmd_remote() modified to protect some NV items remote\r
56                    read/write access under FEATURE_NV_ACCESS_FILTER\r
57 03/18/09   sri     NV task priority is kept unchanged.\r
58 01/08/08   pc      Ensured mutex initialization for synchronous calls.\r
59 12/13/07   pc      Introduced kxmutexes around NV access.\r
60 06/08/07   pc      Added support for mdn based nai\r
61 12/15/06   ck      Include the header file fs_diag_access.h\r
62 06/05/05   pc      Created NV-2.\r
63 ===========================================================================*/\r
64 \r
65 /* ======================================================================\r
66 \r
67                        INCLUDE FILES FOR MODULE\r
68 \r
69 ========================================================================*/\r
70 \r
71 #include "target.h"\r
72 #include "comdef.h"\r
73 #include "AEEstd.h"\r
74 #ifdef FEATURE_NV_ITEM_MGR\r
75 \r
76 #include "nvim.h"\r
77 #include "msg.h"\r
78 #include "nvio.h"\r
79 #include "err.h"\r
80 #include "task.h"\r
81 #include "dog.h"\r
82 #include "crc.h"\r
83 #include "memory.h"\r
84 #include "fs_public.h"\r
85 #include "nv_items.h"\r
86 #include "fs_diag_access.h"\r
87 \r
88 #ifdef FEATURE_CDMA1X\r
89   #include "mc.h"\r
90 #else\r
91   #include "tmc.h"\r
92 #endif\r
93 \r
94 #ifdef FEATURE_TREX\r
95 #error code not present\r
96 #endif\r
97 #include "nvim_items.h"\r
98 #ifdef FEATURE_TREX\r
99 #error code not present\r
100 #endif\r
101 \r
102 #ifdef FEATURE_NV_RUIM\r
103 #include "nvruimi.h"\r
104 #endif\r
105 \r
106 #ifdef FEATURE_NV_CNV\r
107 #include "fs_public.h"\r
108 #include "nv_cnv.h"\r
109 #endif\r
110 \r
111 #ifdef FEATURE_MDN_BASED_NAI\r
112 #define PS_NAI_DFLT_DOMAIN "@default.com"\r
113 #include "dsmip.h"\r
114 #endif /* FEATURE_MDN_BASED_NAI */\r
115 \r
116 #ifdef FEATURE_WINCE\r
117 #error code not present\r
118 #else\r
119   #ifdef FEATURE_QUARTZ_135\r
120     #include "quartz/KxMutex.h"\r
121   #else\r
122     #include <KxMutex.h>\r
123   #endif\r
124 #endif\r
125 \r
126 #include <stdlib.h> \r
127 \r
128 \f \r
129 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
130 /*                                                                         */\r
131 /*                         DATA DEFINITIONS                                */\r
132 /*                                                                         */\r
133 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
134 \r
135 static KxMutex nv_access_op_cs;\r
136 \r
137 extern rex_crit_sect_type nv_crit_sect;\r
138 extern const nvim_item_info_type nvim_item_info_table[];\r
139 extern nv_rtre_control_type nv_rtre_control_value;\r
140 extern nv_rtre_polling_control_type nv_rtre_polling_control_value;\r
141 \r
142 #ifdef FEATURE_NV_CNV\r
143 /* File to back up the data into */\r
144 const char   *cnv_file = "/nvm/nv_cnv.bin";\r
145 #endif\r
146 \r
147 boolean  nvi_task_running=FALSE;\r
148 \r
149 /* Contains the roaming list "valid" indicator */\r
150 boolean  nv_prl_valid_data[NV_MAX_NAMS];\r
151 \r
152 /* Contains the roaming list "prl_version" field */\r
153 word     nv_prl_version_data[NV_MAX_NAMS];\r
154 \r
155 /* Buffer holding the union of all internal NVM storage types.  Use as    */\r
156 /* a working buffer when reading or writing data from or to NVM and the   */\r
157 /* data requires translation between internal format and external format. */\r
158 nvi_item_type  nvi_item;\r
159 \r
160 /* Data buffer for individual writes/reads issued internally. */  \r
161 nv_item_type  local_item;  \r
162 \r
163 /* Command buffer for individual writes/reads issued internally. */\r
164 nv_cmd_type   local_cmd; \r
165 \r
166 #ifdef NV_FEATURE_PRL_ITEMS\r
167 /* Globally used buffer to contain the roaming list read-from  */ \r
168 /* or written-to NV memory.                                    */\r
169 nv_roaming_list_type   nv_pr_list; \r
170 #endif\r
171 \r
172 #ifdef NV_FEATURE_RENTAL_ITEMS\r
173 #error code not present\r
174 #endif\r
175 \r
176 /* Dynamic pool available in EFS */\r
177 word                   nvi_memavail_data=0;\r
178 \r
179 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
180 /*                                                                         */\r
181 /*                      REX Timers and Queues                              */\r
182 /*                                                                         */\r
183 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
184 \r
185 rex_timer_type         nv_rpt_timer;     /* NV watchdog report timer. */\r
186 rex_timer_type         nv_write_timer;   /* NVM write timer. */\r
187 LOCAL q_type           nv_cmd_q;         /* NV task command queue. */\r
188 \r
189 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
190 /*                                                                         */\r
191 /*                            Local Data                                   */\r
192 /*                                                                         */\r
193 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
194 \r
195 \r
196 /* Flag to determine if EEPROM initialization has occurred    */\r
197 static boolean                 nvi_initialized = FALSE;\r
198 \r
199 /* Flag to determine if kxmutex initialization has occured */\r
200 static boolean                 nv_cs_init_flag = FALSE;\r
201 \r
202 /* The total factory data block cache for peek/poke access */\r
203 byte fact_data[NVIM_FACTORY_DATA_SIZE];\r
204 \r
205 static boolean          nverr_init( void );\r
206 static void             nverr_update_log( void );\r
207 \r
208 extern void nvdiag_init (void);\r
209 \r
210 /* Structure used to essentially double buffer the error log  */\r
211 struct \r
212 {\r
213   nv_err_log_type  external[NV_MAX_ERR_LOG];\r
214   nv_err_log_type  internal[NV_MAX_ERR_LOG];\r
215   boolean          update_required[NV_MAX_ERR_LOG];\r
216   boolean          update_in_progress[NV_MAX_ERR_LOG];\r
217   boolean          processing_required;\r
218 } nverr_log;\r
219 \r
220 #if defined( FEATURE_UIM_RUN_TIME_ENABLE )\r
221 /* Run Time R-UIM Enable control.  Default: do not use the R-UIM */\r
222 #ifdef FEATURE_RTRE_DEFAULT_IS_NV\r
223 nv_rtre_control_type nv_rtre_control_value = NV_RTRE_CONTROL_NO_RUIM;\r
224 #else\r
225 nv_rtre_control_type nv_rtre_control_value = NV_RTRE_CONTROL_USE_RUIM;\r
226 #endif\r
227 /* Run Time R-UIM Enable polling control.  Default:  do not poll */\r
228 nv_rtre_polling_control_type nv_rtre_polling_control_value = \r
229   NV_RTRE_POLLING_CONTROL_NO_POLL;\r
230 #endif /* FEATURE_UIM_RUN_TIME_ENABLE */\r
231 \r
232 #ifdef FEATURE_DIAG_FS_ACCESS_VALIDATION\r
233   #ifdef FEATURE_EFS2\r
234     #include "fs_diag.h"\r
235   #else\r
236     #include "fsdiag.h"\r
237   #endif\r
238 \r
239 static const char *nv_access_dirs[] = {\r
240   "nvm"\r
241 };\r
242 \r
243 #endif\r
244 \r
245 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
246 /*                                                                         */\r
247 /*                            Debug Data                                   */\r
248 /*                                                                         */\r
249 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
250 \r
251 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
252 /*                                                                         */\r
253 /*                               Macros                                    */\r
254 /*                                                                         */\r
255 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
256 \r
257 \r
258 #ifdef FEATURE_DIAG_FS_ACCESS_VALIDATION\r
259 \r
260 /*==================================================================\r
261 Function: NV_CHECK_REMOTE_ACCESS\r
262 \r
263 Description: This functions returns access permissions for \r
264              directories specified by input parameter "path".\r
265 ==================================================================*/\r
266 static boolean\r
267 nv_check_remote_access (char *path, uint32 op_type)\r
268 {\r
269   (void) path;\r
270   (void) op_type;\r
271  #ifdef FEATURE_TECHNICS_DIAG\r
272   return TRUE;\r
273 #else\r
274   return FALSE;\r
275 #endif\r
276 \r
277 }\r
278 \r
279 /*====================================================================\r
280 Function: NV_REGISTER_REMOTE_ACCESS_CHECK\r
281 \r
282 Description: Registers callback function nv_check_remote_access()\r
283              with directory listed in nv_access_dirs. On any access to\r
284              nv_access_dirs directories, nv_check_remote_access will \r
285              be called to determine access permissions.\r
286 =====================================================================*/\r
287 void\r
288 nv_register_remote_access_check (void)\r
289 {\r
290   diag_fs_register_access_check (nv_access_dirs, 1, nv_check_remote_access);\r
291 }\r
292 #endif /* FEATURE_DIAG_FS_ACCESS_VALIDATION */\r
293 \r
294 \f\r
295 /*===========================================================================\r
296 \r
297 FUNCTION NV_READ_ERR_LOG\r
298 \r
299 DESCRIPTION\r
300   This function reads an error log from NVM.\r
301 \r
302 DEPENDENCIES\r
303   The function MUST NOT USE ANY TASK SERVICES, so that it can be\r
304   called when tasks are not initialized.  The function MUST NOT\r
305   USE ERROR SERVICES.  It returns status to the caller if there\r
306   is a failure.\r
307 \r
308 RETURN VALUE\r
309   NV_DONE_S         if it worked\r
310   NV_NOT_ACTIVE_S   if item was not active\r
311   NV_FAIL_S         if item could not be read\r
312 \r
313 SIDE EFFECTS\r
314   None.\r
315 \r
316 ===========================================================================*/\r
317 \r
318 nv_stat_enum_type \r
319 nv_read_err_log (\r
320   nv_err_log_type  *nv_err_log_ptr    /* Pointer where to return read data */\r
321 )\r
322 {\r
323   word isave;     /* Save processor flags */\r
324 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
325 \r
326   if(!nvi_initialized) {\r
327     return NV_DONE_S; /* can not read errors before nv built */\r
328   }\r
329 \r
330   /* check and reject illegal request. */\r
331   if (nv_err_log_ptr->address >= NV_MAX_ERR_LOG) {\r
332     return NV_FAIL_S;\r
333   }\r
334 \r
335   /* copy the shadow copy of the error log */\r
336   INTLOCK_SAV( isave );         /* Disable interrupts and save PSW */\r
337   nv_err_log_ptr->err_count = nverr_log.external[nv_err_log_ptr->address].err_count;\r
338   std_strlcpy((char *)nv_err_log_ptr->file_name,\r
339               (char *)nverr_log.external[nv_err_log_ptr->address].file_name,\r
340               sizeof(nv_err_log_ptr->file_name));\r
341   nv_err_log_ptr->line_num = nverr_log.external[nv_err_log_ptr->address].line_num;\r
342   nv_err_log_ptr->fatal = nverr_log.external[nv_err_log_ptr->address].fatal;\r
343   INTFREE_SAV( isave );         /* Restore interrupts (PSW) */\r
344 \r
345   return NV_DONE_S;\r
346 } /* nv_read_err_log */\r
347 \r
348 \f\r
349 /*===========================================================================\r
350 \r
351 FUNCTION NV_WRITE_ERR_LOG\r
352 \r
353 DESCRIPTION\r
354   This function writes the boot error log to NVM.\r
355 \r
356 DEPENDENCIES\r
357   The function MUST NOT USE ANY TASK SERVICES, so that it can be\r
358   called when tasks are not initialized.  The function MUST NOT\r
359   USE ERROR SERVICES.  It returns status to the caller if there\r
360   is a failure.\r
361 \r
362 RETURN VALUE\r
363   NV_DONE_S - if it worked\r
364   NV_FAIL_S - if item could not be written\r
365 \r
366 SIDE EFFECTS\r
367   None.\r
368 \r
369 ===========================================================================*/\r
370 \r
371 nv_stat_enum_type \r
372 nv_write_err_log(\r
373   nv_err_log_type  *nv_err_log_ptr    /* Pointer where to get write data */\r
374 )\r
375 {\r
376    static boolean nv_err_fataling = FALSE;\r
377    nv_stat_enum_type status;       /* NV read status */\r
378    word isave;\r
379    \r
380    /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
381    if (nv_err_fataling) return NV_FAIL_S;\r
382 \r
383    if (!nvi_initialized) {\r
384       return NV_DONE_S; /* can not write errors before nv built */\r
385    }\r
386 \r
387    /* Check if file system is error fataling  */\r
388    if ((rex_self() == &fs_tcb) && (nv_err_log_ptr->fatal)) {\r
389       nv_err_fataling = TRUE; /* NV is not usable once FS err fatals */\r
390       return NV_DONE_S; /* can not write this error */\r
391    }\r
392    \r
393    /* check and reject illegal request. */\r
394 \r
395    if (nv_err_log_ptr->address >= NV_MAX_ERR_LOG) {\r
396       return NV_FAIL_S;\r
397    }\r
398    /* If the task is running we queue the write to the nv part as to not\r
399     * interrupt a write in progress. This is a somewhat device dependend\r
400     * concept in that we assume a write can not be safely interrupted during\r
401     * a write, which is not true of all nv devices. \r
402     * Note that error_fatals always take the direct route.\r
403     */\r
404    if (nvi_task_running && !(nv_err_log_ptr->fatal)) {\r
405       /* put error into shadow copy of nv error record */\r
406       INTLOCK_SAV(isave);\r
407       nverr_log.processing_required = TRUE;\r
408       (void) memcpy((void *)&(nverr_log.external[nv_err_log_ptr->address]), \r
409                     (void *)nv_err_log_ptr,\r
410                     sizeof(nv_err_log_type));          /* data buffer size */\r
411       nverr_log.update_required[nv_err_log_ptr->address] = TRUE;\r
412       INTFREE_SAV(isave);\r
413 \r
414       /* Signal the nv task that there is a buffer to process */\r
415       (void) rex_set_sigs(&nv_tcb, NV_ERR_LOG_SIG);\r
416       return NV_DONE_S;\r
417    }\r
418    else {\r
419       if ((nv_err_log_ptr->fatal)) {\r
420          nv_err_fataling = TRUE;\r
421          /* allow lower levels to run with ints disabled */\r
422          nvi_task_running = FALSE; \r
423       }\r
424 \r
425       status = nvio_write_item\r
426                ( NV_ERR_LOG_I, \r
427                  nv_err_log_ptr->address, /* Item index within its array */\r
428                  (void *)&nv_err_log_ptr->err_count,         /* data buffer */ \r
429                  nvim_op_get_size(NV_ERR_LOG_I),\r
430                  0 /* context=0 implies no context is defined */\r
431                );\r
432 \r
433       INTLOCK_SAV(isave);\r
434       if (!(nv_err_log_ptr->fatal)) {\r
435          (void) memcpy((void *)&(nverr_log.external[nv_err_log_ptr->address]), \r
436                        (void *)nv_err_log_ptr,\r
437                        sizeof(nv_err_log_type));          /* data buffer size */\r
438       }\r
439       INTFREE_SAV(isave);\r
440 \r
441       return status;\r
442    }\r
443 } /* nv_write_err_log */\r
444 \r
445 /*===========================================================================\r
446 \r
447 FUNCTION NVIM_OP_GET_PRESENCE\r
448 \r
449 DESCRIPTION\r
450   This function determines whether an entry is present.\r
451 \r
452 DEPENDENCIES\r
453   None.\r
454 \r
455 RETURN VALUE\r
456   0 : NVIM_NOT_PRESENT : Not present\r
457   1 : NVIM_PRESENT : Present\r
458   2 : NVIM_WRITE_ONCE : Present and write once only\r
459 \r
460 SIDE EFFECTS\r
461 \r
462 ===========================================================================*/\r
463 boolean \r
464 nvim_op_get_presence (\r
465   nv_items_enum_type item   /* Item ID */\r
466 )\r
467 {\r
468   if (item < NVIM_ITEM_INFO_TABLE_SIZE)\r
469   {\r
470     return nvim_item_info_table[item].is_present;\r
471   }\r
472   else\r
473   {\r
474     ERR("Item code %d out of range", item, 0, 0);\r
475     return 0;\r
476   }\r
477 \r
478 } /* nvim_op_get_presence */\r
479 \r
480 \f\r
481 /*===========================================================================\r
482 \r
483 FUNCTION NVIM_OP_GET_ARRAY_SIZE\r
484 \r
485 DESCRIPTION\r
486   This function returns the array size of an item, given its ID (item code).\r
487 \r
488 DEPENDENCIES\r
489   None.\r
490 \r
491 RETURN VALUE\r
492   Array size.\r
493 \r
494 SIDE EFFECTS\r
495   Only a meaningful return value if the entry is valid which is determined\r
496   by calling nv_op_is_valid_entry\r
497 \r
498 ===========================================================================*/\r
499 uint16 \r
500 nvim_op_get_array_size (\r
501   nv_items_enum_type   item   /* Item ID */\r
502 )\r
503 {\r
504   if (item < NVIM_ITEM_INFO_TABLE_SIZE) {\r
505     return nvim_item_info_table[item].array_size;\r
506   }\r
507   else {\r
508     ERR("Item %d out of range", item, 0, 0);\r
509     return 0;\r
510   }\r
511 } /* nvim_op_get_array_size */\r
512 \r
513 \r
514 \f\r
515 /*===========================================================================\r
516 \r
517 FUNCTION NVIM_OP_GET_SIZE\r
518 \r
519 DESCRIPTION\r
520   This function returns the size of an item, given its ID (item code).\r
521 \r
522 DEPENDENCIES\r
523   None.\r
524 \r
525 RETURN VALUE\r
526   Item size.\r
527 \r
528 SIDE EFFECTS\r
529   Only a meaningful return value if the entry is valid which is determined\r
530   by calling nv_op_is_valid_entry\r
531 \r
532 ===========================================================================*/\r
533 uint32 \r
534 nvim_op_get_size (\r
535   nv_items_enum_type   item   /* Item ID */\r
536 )\r
537 {\r
538   if (item < NVIM_ITEM_INFO_TABLE_SIZE)\r
539   {\r
540     return (nvim_item_info_table[item].item_size);\r
541   }\r
542   else\r
543   {\r
544     ERR("Item %d out of range", item, 0, 0);\r
545     return 0;\r
546   }\r
547 } /* nvim_op_get_size */\r
548 \r
549 \r
550 \f\r
551 /*===========================================================================\r
552 \r
553 FUNCTION NV_DETERMINE_ESN_VALIDITY\r
554 \r
555 DESCRIPTION\r
556   This function is determines if the current ESN has been programmed with the\r
557   status of this check returned.\r
558 \r
559 DEPENDENCIES\r
560   None.\r
561 \r
562 RETURN VALUE\r
563   TRUE if the current ESN is non-zero with proper checksums, else FALSE\r
564 \r
565 SIDE EFFECTS\r
566 \r
567 ===========================================================================*/\r
568 \r
569 boolean \r
570 nv_determine_esn_validity( void)\r
571 {\r
572   /* This is gross, but there is not enough stack space\r
573    *  for these next two items so we declare them as the appear in the enum\r
574    */\r
575   dword             nv_item1_esn;        /* tmp buffer for esn */\r
576   dword             nv_item2_esn_chksum; /* tmp buffer for esn checksum */\r
577   nv_stat_enum_type status;              /* to get status of NV operations */\r
578 \r
579 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
580 \r
581   /* Start by reading the ESN and returning FALSE if it is now -1        */\r
582 \r
583   status = nvio_read_item(NV_ESN_I,/* file handle */\r
584                           0,       /* file position */\r
585                           &nv_item1_esn,          /* data ptr */\r
586                           sizeof(nv_item1_esn), /* data count */\r
587                           0); /* context=0 implies no context is defined */\r
588 \r
589   if( (status != NV_DONE_S) ||\r
590       (nv_item1_esn == 0xFFFFFFFF) )  {\r
591     /* ------------------------- */\r
592     /* The ESN has not been set, */\r
593     /* return FALSE              */\r
594     /* ------------------------- */\r
595     ERR( "ESN has not been set", 0, 0, 0);\r
596     return FALSE;\r
597   }\r
598 \r
599   if( nv_item1_esn == 0 )  {\r
600     QSR_MSG_HIGH( 1495149522ULL, "ESN is zero for factory test",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
601   }\r
602 \r
603   /* --------------------------------------------------------------------- */\r
604   /* To get here the ESN has been set. Determine if the checksums are      */\r
605   /* valid. Do this be comparing calculated checksums against stored sums  */\r
606   /* --------------------------------------------------------------------- */\r
607  \r
608   status = nvio_read_item(NV_ESN_CHKSUM_I,/* file handle */\r
609                           0,       /* file position */\r
610                           &nv_item2_esn_chksum,          /* data ptr */\r
611                           sizeof(nv_item2_esn_chksum), /* data count */\r
612                           0); /* context=0 implies no context is defined */\r
613 \r
614   /* --------------------------------------------------------------------- */\r
615   /* To get here the ESN is valid and this is not a pre-Version 5.      */\r
616   /* Check for proper checksums and return TRUE if so, else return FALSE   */\r
617   /* --------------------------------------------------------------------- */\r
618 \r
619   if( crc_30_calc( (byte *)&nv_item1_esn, sizeof(nv_item1_esn) * 8) !=\r
620       nv_item2_esn_chksum)  {\r
621     /* ------------------------- */\r
622     /* The ESN checksum is not   */\r
623     /* valid, return FALSE       */\r
624     /* ------------------------- */\r
625     ERR( "Stored ESN CHKSUM bad: %u", nv_item2_esn_chksum, 0, 0);\r
626     return FALSE;\r
627   } else {\r
628     return TRUE;\r
629   }\r
630 }\r
631 \r
632 \f\r
633 #ifdef FEATURE_NV_CNV\r
634 /*======================================================================\r
635 FUNCTION NVI_CNV_CHECK\r
636 \r
637 DESCRIPTION\r
638   This function checks for the presence of a CNV file in EFS.\r
639   If it is found, the items are inserted into the current nv.\r
640 \r
641 DEPENDENCIES\r
642   EFS must be initialized.  The item manager must also have completed\r
643   nv_init.  This routine expects to be called at the end of NV_INIT.\r
644 \r
645 RETURN VALUE\r
646   None\r
647 \r
648 SIDE EFFECTS\r
649   NV items could be updated if a valid CNV fileis present.\r
650 \r
651 ======================================================================*/\r
652 void nvim_cnv_check(void)\r
653 {\r
654   int       file_handle = NULL;\r
655   struct    fs_stat sbuf;\r
656   fs_off_t  offset;\r
657   fs_size_t size;\r
658   word      crc16;\r
659   static    byte buffer[32];\r
660   uint32    count;\r
661   uint32    size_left;\r
662   uint8     pad_size;\r
663 \r
664 \r
665   cnv_item_hdr_type item_head;\r
666   static nv_item_type      item;\r
667   nv_cmd_type       cmd;\r
668   nv_cmd_ext_type   cmd_ext;\r
669 \r
670   /* Open the file */\r
671   file_handle = efs_open(cnv_file, O_RDWR);\r
672   if (file_handle < 0)\r
673   {\r
674     QSR_MSG_HIGH ( 1964571546ULL, "Cannot open CNV file", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
675     return;\r
676   }\r
677 \r
678   /* Stat to get the file size */\r
679   if (efs_fstat(file_handle, &sbuf) < 0)\r
680   {\r
681     QSR_MSG_HIGH ( 945998922ULL, "Error on fstat of CNV file",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
682     return;\r
683   }\r
684 \r
685   /* Cycle thru the contents to check CRC */\r
686   crc16 = (word) CRC_16_STEP_SEED;\r
687 \r
688   size_left = sbuf.st_size;\r
689   while (size_left > 0) {\r
690     count = size_left;\r
691     if (count > sizeof (buffer))\r
692       count = sizeof (buffer);\r
693 \r
694     size = efs_read(file_handle, buffer, count);\r
695     if (size != count)\r
696     {\r
697       QSR_MSG_MED ( 2881874282ULL, "Unable to read CNV data", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
698       return;\r
699     }\r
700 \r
701     crc16 = crc_16_step (crc16, buffer, count);\r
702     size_left -= count;\r
703   }\r
704 \r
705   if (crc16 != CRC_16_OK) {\r
706     QSR_MSG_HIGH ( 2303037548ULL, "Invalid CRC for CNV data", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
707     return;\r
708   }\r
709 \r
710   QSR_MSG_MED ( 2373619479ULL, "Valid CNV file detected", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
711 \r
712   /* Rewind the file back to the first item and ignore the header\r
713      for now */\r
714   offset = efs_lseek (file_handle, sizeof(cnv_header_type), SEEK_SET);\r
715 \r
716   if (offset < 0)\r
717   {\r
718     QSR_MSG_HIGH ( 1998497732ULL, "Cannot seek to the beginning of the file",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
719     return;\r
720   }\r
721 \r
722   size_left = sbuf.st_size - (sizeof(cnv_header_type) + sizeof(crc16)\r
723                                           + sizeof(cnv_item_hdr_type));\r
724 \r
725   while (size_left > 0)\r
726   {\r
727     /* Read in an item. */\r
728     size = efs_read (file_handle, (void *) &item_head, sizeof (item_head));\r
729     if (size != sizeof (item_head))\r
730     {\r
731       QSR_MSG_MED ( 1772854668ULL, "Unable to read handover item header", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
732       return;\r
733     }\r
734 \r
735     size_left -= sizeof (item_head);\r
736 \r
737     QSR_MSG_MED ( 852213282ULL, "CNV item: %d, size %d", item_head.nv_item_number,\r
738                item_head.nv_item_size, 0);//auto-gen, to change remove 'QSR_' and first param\r
739 \r
740     /* Read in the raw data. */\r
741     size = efs_read (file_handle, (void *) &item, item_head.nv_item_size);\r
742     if (size != item_head.nv_item_size)\r
743     {\r
744       QSR_MSG_MED ( 267230007ULL, "Unable to read CNV item", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
745       return;\r
746     }\r
747 \r
748     /* Write the item to NV. */\r
749     cmd.item     = (nv_items_enum_type) item_head.nv_item_number;\r
750     cmd.cmd      = NV_WRITE_F;\r
751     cmd.data_ptr = &item;\r
752 \r
753     cmd_ext.nvcmd = &cmd;\r
754     cmd_ext.context  = 0;\r
755 \r
756     if (nvio_write (&cmd_ext) != NV_DONE_S)\r
757     {\r
758       QSR_MSG_HIGH ( 1264321974ULL, "Unable to write handover item: %d, size %d",\r
759                  item_head.nv_item_number, item_head.nv_item_size, 0);//auto-gen, to change remove 'QSR_' and first param\r
760     }\r
761 \r
762     pad_size = 0;\r
763     if ((item_head.nv_item_size % 4) != 0)\r
764     {\r
765       pad_size = 4 - (item_head.nv_item_size % 4);\r
766 \r
767       offset = efs_lseek(file_handle, pad_size, SEEK_CUR);\r
768       if (offset < 0)\r
769       {\r
770         QSR_MSG_HIGH ( 1039740364ULL, "Cannot seek forward to the next item",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
771         return;\r
772       }\r
773     }\r
774     size_left -= (item_head.nv_item_size + pad_size);\r
775   }\r
776 \r
777   /* Close the file */\r
778   efs_close (file_handle);\r
779 \r
780   /* Remove the file since we are done updating the NV items */\r
781   if (efs_unlink (cnv_file) < 0)\r
782   {\r
783     QSR_MSG_HIGH ( 2406613708ULL, "Unable to remove CNV file", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
784   }\r
785 } /* nvi_cnv_check */\r
786 \r
787 #endif /*FEATURE_NV_CNV*/\r
788 \r
789 \f\r
790 /*===========================================================================\r
791 \r
792 FUNCTION NVIM_BUILD_SEC\r
793 \r
794 DESCRIPTION\r
795   This function builds all NVM variables.\r
796 \r
797 DEPENDENCIES\r
798 \r
799 RETURN VALUE\r
800   NV_DONE_S if it worked\r
801   NV_FAIL_S if a variable could not be initialized.\r
802 \r
803 SIDE EFFECTS\r
804 \r
805 ===========================================================================*/\r
806 \r
807 static nv_stat_enum_type \r
808 nvim_build_sec(void)\r
809 {\r
810    nv_stat_enum_type  status;    /* Status to return to calling procedure */\r
811    word               cnt;       /* Counter for attempts to write variable */\r
812    nv_cmd_ext_type    local_cmd_ext;\r
813    \r
814    /* Initialize the lock code to the default value (0000)   */\r
815    for( cnt=0; cnt<NV_LOCK_CODE_SIZE; cnt++)  {\r
816      local_item.lock_code.digits[ cnt] = '0';\r
817    }\r
818    \r
819    local_cmd.item       = NV_LOCK_CODE_I;\r
820    local_cmd.tcb_ptr    = NULL;\r
821    local_cmd.sigs       = 0;\r
822    local_cmd.done_q_ptr = NULL;\r
823    local_cmd.cmd        = NV_WRITE_F;\r
824    local_cmd.data_ptr   = &local_item;\r
825    \r
826    local_cmd_ext.nvcmd = &local_cmd;\r
827    local_cmd_ext.context = 0; /* No context is defined */\r
828 \r
829    status = nvio_write(&local_cmd_ext);\r
830    if(status != NV_DONE_S)\r
831    {\r
832       return status;\r
833    }\r
834    \r
835    /* Initialize the sec code to the default value (0000)   */\r
836    for( cnt=0; cnt<NV_SEC_CODE_SIZE; cnt++)  {\r
837      local_item.sec_code.digits[ cnt] = '0';\r
838    }\r
839    local_cmd.item       = NV_SEC_CODE_I;\r
840    local_cmd.tcb_ptr    = NULL;\r
841    local_cmd.sigs       = 0;\r
842    local_cmd.done_q_ptr = NULL;\r
843    local_cmd.cmd        = NV_WRITE_F;\r
844    local_cmd.data_ptr   = &local_item;\r
845    \r
846    local_cmd_ext.nvcmd = &local_cmd;\r
847    local_cmd_ext.context = 0; /* No context is defined */\r
848 \r
849    status = nvio_write(&local_cmd_ext);\r
850 \r
851    return status;\r
852 }\r
853 \r
854 \f\r
855 /*===========================================================================\r
856 \r
857 FUNCTION NVIM_CLEAR_CRCS\r
858 \r
859 DESCRIPTION\r
860   This function is called to clear CRCs in NV when the NV is built. The function \r
861   clears the NAM checksums, the MIN checksums within each NAM, and, if \r
862   the ESN and IMEI have not already been written (assigned), the ESN, the IMEI,\r
863   the ESN checksum, the IMEI checksum.  This action lets higher level tasks \r
864   know that these parameters are not valid and that service programming is \r
865   required.\r
866 \r
867 DEPENDENCIES\r
868   NVM must have been built.\r
869 \r
870 RETURN VALUE\r
871   NV_DONE_S if it worked\r
872   NV_FAIL_S if the EEPROM access has failed\r
873 \r
874 SIDE EFFECTS\r
875   NV parameters identified above are zeroed.\r
876 \r
877 ===========================================================================*/\r
878 \r
879 LOCAL nv_stat_enum_type  \r
880 nvim_clear_crcs (void)\r
881 {\r
882   byte                nam_idx;       /* NAM counter */\r
883   byte                min_idx;       /* MIN counter */\r
884   nv_cmd_ext_type    local_cmd_ext;\r
885 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
886 \r
887   /* Setup command buffer parameters. */\r
888 \r
889   local_cmd.cmd = NV_WRITE_F;\r
890   local_cmd.tcb_ptr = NULL;\r
891   local_cmd.sigs = 0;\r
892   local_cmd.done_q_ptr = NULL;\r
893   local_cmd.data_ptr = &local_item;\r
894 \r
895   /* Clear all NAMs checksums and the MIN checksums for each NAM. */\r
896   \r
897   for (nam_idx = 0; nam_idx < NV_MAX_NAMS; nam_idx++) { \r
898     local_item.nam_chksum.nam = nam_idx;\r
899     local_item.nam_chksum.chksum = 0;\r
900     local_cmd.item = NV_NAM_CHKSUM_I;\r
901 \r
902     local_cmd_ext.nvcmd = &local_cmd;\r
903     local_cmd_ext.context = 0; /* No context is defined */\r
904 \r
905     local_cmd.status = nvio_write(&local_cmd_ext);\r
906 \r
907     QSR_MSG_LOW( 705624602ULL, "NAM %d NAM checksum zero status %d", nam_idx, local_cmd.status, 0);//auto-gen, to change remove 'QSR_' and first param\r
908     if (local_cmd.status != NV_DONE_S) {\r
909       return (local_cmd.status);\r
910     }\r
911  \r
912     local_item.min_chksum.nam = nam_idx;\r
913     for (min_idx = 0; min_idx < NV_MAX_MINS; min_idx++) {\r
914       local_item.min_chksum.chksum[min_idx] = 0;\r
915     }\r
916     local_cmd.item = NV_MIN_CHKSUM_I;\r
917 \r
918     local_cmd_ext.nvcmd = &local_cmd;\r
919     local_cmd_ext.context = 0; /* No context is defined */\r
920 \r
921     local_cmd.status = nvio_write(&local_cmd_ext);\r
922 \r
923     QSR_MSG_LOW( 1811374263ULL, "NAM %d MIN checksum zero status %d", nam_idx, local_cmd.status, 0);//auto-gen, to change remove 'QSR_' and first param\r
924     if (local_cmd.status != NV_DONE_S) {\r
925       return (local_cmd.status);\r
926     }\r
927   } /* for */\r
928 \r
929   /* --------------------------------------------------------------------- */\r
930   /* Next we determine if the ESN is now proper and if not then clear the  */\r
931   /* ESN,the ESN checksum, and the ESN valid flag.                         */\r
932   /* --------------------------------------------------------------------- */\r
933   if( nv_determine_esn_validity() == FALSE) {\r
934     /* ------------------------------------------------------------------- */\r
935     /* The ESN has not yet been assigned/written. Zero associated items    */\r
936     /* Note that to get here status == NV_DONE_S                           */\r
937     /* ------------------------------------------------------------------- */\r
938     local_item.esn.esn = 0;\r
939     local_cmd.item = NV_ESN_I;\r
940 \r
941     local_cmd_ext.nvcmd = &local_cmd;\r
942     local_cmd_ext.context = 0; /* No context is defined */\r
943 \r
944     local_cmd.status = nvio_write(&local_cmd_ext);\r
945     \r
946     QSR_MSG_LOW( 983002661ULL, "ESN zero status %d", local_cmd.status, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
947     if (local_cmd.status != NV_DONE_S) {\r
948       return local_cmd.status;\r
949     }\r
950   }\r
951   return local_cmd.status;\r
952 } /* nvim_clear_crcs */\r
953 \r
954 \f\r
955 /*===========================================================================\r
956 \r
957 FUNCTION NVIM_INIT_RENTAL_TIMER\r
958 \r
959 DESCRIPTION\r
960   This function reads the rental timer item structure out of NVRAM and\r
961   initializes the "nv_rental_item_image" state data item.  It also\r
962   validates the data structure and recovers from a previous bad powerdown.\r
963 \r
964 DEPENDENCIES\r
965   None.\r
966 \r
967 RETURN VALUE\r
968   NV_DONE_S if it worked\r
969   NV_FAIL_S if the EEPROM access has failed\r
970 \r
971 SIDE EFFECTS\r
972   None.\r
973 \r
974 ===========================================================================*/\r
975 \r
976 LOCAL nv_stat_enum_type  \r
977 nvim_init_rental_timer (void) \r
978 {\r
979 \r
980 #ifdef NV_FEATURE_RENTAL_ITEMS\r
981 #error code not present\r
982 #endif\r
983   return NV_DONE_S;\r
984 }\r
985 \r
986 \f\r
987 /*===========================================================================\r
988 \r
989 FUNCTION NVIM_INIT_RENTAL_CNT\r
990 \r
991 DESCRIPTION\r
992   This function reads the rental count item from NV and initializes \r
993   the "nv_rental_cnt_image" state data item.  \r
994   \r
995 DEPENDENCIES\r
996   None.\r
997 \r
998 RETURN VALUE\r
999   NV_DONE_S if it worked\r
1000   NV_FAIL_S if the EEPROM access has failed\r
1001 \r
1002 SIDE EFFECTS\r
1003   None.\r
1004 \r
1005 ===========================================================================*/\r
1006 \r
1007 LOCAL nv_stat_enum_type  \r
1008 nvim_init_rental_cnt (void) {\r
1009 #ifdef NV_FEATURE_RENTAL_ITEMS\r
1010 #error code not present\r
1011 #else\r
1012   return NV_DONE_S;\r
1013 #endif\r
1014 }\r
1015 \r
1016 \f\r
1017 /*===========================================================================\r
1018 \r
1019 FUNCTION NVIM_INIT_PRL_DATA\r
1020 \r
1021 DESCRIPTION\r
1022   This function initializes the "prl_valid_data" and "prl_version_data"\r
1023   state data items.  These are maintained as NV state data so the functions\r
1024   "nv_prl_is_valid()" and "nvim_prl_version()" can return an immediate \r
1025   response.  \r
1026 \r
1027 DEPENDENCIES\r
1028   None.\r
1029 \r
1030 RETURN VALUE\r
1031   NV_DONE_S if it worked\r
1032   NV_FAIL_S if failed\r
1033 \r
1034 SIDE EFFECTS\r
1035   None.\r
1036 \r
1037 ===========================================================================*/\r
1038 \r
1039 LOCAL void\r
1040 nvim_init_prl_data (void) \r
1041 {\r
1042   byte                         nam;\r
1043   nv_roaming_list_header_type  prl_header;\r
1044   nv_stat_enum_type            status;\r
1045 \r
1046   prl_header.nam =  FALSE;\r
1047   prl_header.prl_version = 0;\r
1048   prl_header.valid = FALSE;\r
1049 \r
1050   for (nam=0; nam<NV_MAX_NAMS; nam++) {\r
1051     /* For each nam, read the prl header */\r
1052     status = nvio_read_prl_item(nam,\r
1053                                 (void *)&prl_header,               /* data ptr */\r
1054                                 NV_ROAMING_LIST_HEADER_SIZE);/* data count */\r
1055     /* Set state data items -- note that the item's active flag */\r
1056     /* occupies the "nam" field in the external type.           */\r
1057     if (status == NV_DONE_S) {\r
1058       nv_prl_version_data[nam] = prl_header.prl_version;\r
1059       nv_prl_valid_data[nam] = prl_header.valid;\r
1060     }\r
1061     else {\r
1062       nv_prl_version_data[nam] = NV_PRL_VERSION_INVALID;\r
1063       nv_prl_valid_data[nam] = FALSE;\r
1064     }\r
1065   }\r
1066   return;\r
1067 }\r
1068 \r
1069 \f\r
1070 /*===========================================================================\r
1071 \r
1072 FUNCTION NVIM_REMOVE_ITEM\r
1073 \r
1074 DESCRIPTION\r
1075   This procedure processes NVM remove requests for a particular item.\r
1076 \r
1077 DEPENDENCIES\r
1078   None.\r
1079 \r
1080 RETURN VALUE\r
1081   Status of read operation.\r
1082 \r
1083 SIDE EFFECTS\r
1084   None.\r
1085 \r
1086 ===========================================================================*/\r
1087 \r
1088 nv_stat_enum_type \r
1089 nvim_remove_item (\r
1090   nv_cmd_ext_type  *cmd_ext_ptr           /* Pointer to Command block */\r
1091 )\r
1092 {\r
1093   //Filename size is incremented from 20 to 28 to account for context\r
1094   char file_name[28];\r
1095   nv_stat_enum_type status;\r
1096 \r
1097   if ((cmd_ext_ptr->nvcmd->item != NV_SMS_I) && (cmd_ext_ptr->nvcmd->item != NV_SMS_GW_I)) \r
1098     return NV_BADPARM_S;\r
1099 \r
1100 #ifdef FEATURE_NV_RUIM\r
1101   if (cmd_ext_ptr->context == 0) {\r
1102     if ( nvruim_free(cmd_ext_ptr->nvcmd, &status) == NV_RUIM_SUPPORTS_ITEM )\r
1103       return status;\r
1104   }\r
1105 #ifdef FEATURE_DUAL_STANDBY\r
1106   else {\r
1107     if ( nvruim_free_ext(cmd_ext_ptr, &status) == NV_RUIM_SUPPORTS_ITEM )\r
1108         return status;\r
1109   }\r
1110 #endif\r
1111 #endif\r
1112   status = NV_DONE_S;\r
1113 \r
1114   if (cmd_ext_ptr->nvcmd->item >= NV_MAX_I) {\r
1115    status = NV_BADPARM_S;\r
1116   }\r
1117   else {\r
1118     switch(cmd_ext_ptr->nvcmd->item) {\r
1119       case NV_SMS_I:\r
1120       case NV_SMS_DM_I:\r
1121         if(cmd_ext_ptr->nvcmd->data_ptr->sms.address >= NVI_MAX_SMS_ADDR)\r
1122           status = NV_BADPARM_S;\r
1123         else{\r
1124           //If context is not defined, use the old path\r
1125           if (cmd_ext_ptr->context == 0)\r
1126           (void) snprintf(file_name, sizeof(file_name), "/nvm/sms_%05d",\r
1127                                             cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
1128           else //Else, context is defined, use context for path\r
1129             (void) snprintf(file_name, sizeof(file_name), "/nvm/context%d/sms_%05d",\r
1130                                             cmd_ext_ptr->context,cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
1131           efs_unlink(file_name);\r
1132         }\r
1133         break;\r
1134       case NV_SMS_GW_I:\r
1135         if(cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address >= NVI_MAX_SMS_ADDR) \r
1136           status = NV_BADPARM_S;\r
1137         else {\r
1138           //If context is not defined, use the old path\r
1139           if (cmd_ext_ptr->context == 0)\r
1140           (void) snprintf(file_name, sizeof(file_name), "/nvm/sms_gw_%05d",\r
1141                                           cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
1142           else //Else, context is defined, use context for path\r
1143             (void) snprintf(file_name, sizeof(file_name), "/nvm/context%d/sms_gw_%05d",\r
1144                                           cmd_ext_ptr->context,cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
1145           efs_unlink(file_name);\r
1146         }\r
1147         break;\r
1148       default:\r
1149         status = NV_BADPARM_S;\r
1150     }/*switch*/\r
1151   }/* else */\r
1152   return status;\r
1153 }/*nvim_remove_item*/\r
1154 \r
1155 \f\r
1156 /*===========================================================================\r
1157 \r
1158 FUNCTION NVIM_REMOVE_ALL\r
1159 \r
1160 DESCRIPTION\r
1161   This removes all files under the NVM directory\r
1162 \r
1163 DEPENDENCIES\r
1164   None.\r
1165 \r
1166 RETURN VALUE\r
1167   Status of read operation.\r
1168 \r
1169 SIDE EFFECTS\r
1170   None.\r
1171 \r
1172 ===========================================================================*/\r
1173 \r
1174 nv_stat_enum_type \r
1175 nvim_remove_all ( void )\r
1176 {\r
1177   struct fs_dirent         *dirent;\r
1178   EFSDIR *dir;\r
1179 \r
1180   dir = efs_opendir("nvm/sms");\r
1181   while((dirent = efs_readdir(dir))!= NULL){\r
1182     efs_unlink( dirent->d_name );\r
1183   }\r
1184   efs_closedir (dir);\r
1185   efs_rmdir("/nvm/sms");\r
1186 \r
1187   dir = efs_opendir("nvm/prl");\r
1188   while((dirent = efs_readdir(dir))!= NULL){\r
1189     efs_unlink( dirent->d_name );\r
1190   }\r
1191   efs_closedir (dir);\r
1192   efs_rmdir("/nvm/prl");\r
1193 \r
1194   dir = efs_opendir("nvm/nvm");\r
1195   while((dirent = efs_readdir(dir))!= NULL){\r
1196     efs_unlink( dirent->d_name );\r
1197   }\r
1198   efs_closedir (dir);\r
1199   efs_rmdir("/nvm/nvm");\r
1200 \r
1201   dir = efs_opendir("nvm");\r
1202   while((dirent = efs_readdir(dir))!= NULL){\r
1203     efs_unlink( dirent->d_name );\r
1204   }\r
1205   efs_closedir (dir);\r
1206 \r
1207   return NV_DONE_S;\r
1208 }/*nvim_remove_all*/\r
1209 \r
1210 \f\r
1211 /*===========================================================================\r
1212 \r
1213 FUNCTION NVIM_MIGRATION_NEEDED\r
1214 \r
1215 DESCRIPTION\r
1216   This function will decide if there is a need to unlink the nvm directory \r
1217   during a transition of older NV services to NV-2\r
1218 \r
1219 DEPENDENCIES\r
1220   None.\r
1221 \r
1222 RETURN VALUE\r
1223   0 if migration is not required\r
1224   1 if migratuion is required\r
1225   \r
1226 SIDE EFFECTS\r
1227   None.\r
1228 \r
1229 ===========================================================================*/\r
1230 \r
1231 LOCAL int \r
1232 nvim_migration_needed(void) \r
1233 {\r
1234   struct fs_stat temp_buf;\r
1235   /* Make sure that the change to efs_get is made so that it returns \r
1236   correct value */\r
1237   if(efs_stat("nvm/num/0",&temp_buf) == -1)\r
1238     return 1;\r
1239   else \r
1240     return 0;\r
1241 }\r
1242 \r
1243 \f\r
1244 /*===========================================================================\r
1245 \r
1246 FUNCTION NV_INIT\r
1247 \r
1248 DESCRIPTION\r
1249   This function checks the major version number of the the NV task\r
1250   as stored at edit time, against the major version number of the\r
1251   NV EEPROM as read from NVM.  If the numbers are different then the\r
1252   function completely rebuilds the NV EEPROM.  If the major version\r
1253   number has not changed then the function checks if the number of\r
1254   items defined in NVI.H has increased from the internal NVM stored\r
1255   items count.  If so then only those new items are built.  Once the\r
1256   NV EEPROM has been initialized the function updates the stored\r
1257   major version number to the one contained in NVI.H.\r
1258 \r
1259 DEPENDENCIES\r
1260   None.\r
1261 \r
1262 RETURN VALUE\r
1263   NV_DONE_S if it worked\r
1264   NV_FAIL_S if the EEPROM access has failed\r
1265 \r
1266 SIDE EFFECTS\r
1267   Rebuilding the NVM takes a significant amount of time, measured in\r
1268   seconds on serial eeprom devices, if NVM is rebuilt. Startup time \r
1269   will vary with the type of EEPROM.\r
1270 \r
1271 ===========================================================================*/\r
1272 \r
1273 LOCAL nv_stat_enum_type  \r
1274 nv_init (void)\r
1275 {\r
1276   nv_stat_enum_type  status;          /* Status to return to caller */\r
1277 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1278 \r
1279   if(!nv_cs_init_flag)\r
1280     nv_access_op_cs_init();\r
1281 \r
1282   NV_GLOBAL_LOCK_INIT();\r
1283   if (nvim_migration_needed()) {\r
1284     status = nvim_remove_all();\r
1285     if ((status = nvim_build_sec()) == NV_DONE_S) {\r
1286       status = nvim_clear_crcs();\r
1287     }\r
1288   } \r
1289   else {\r
1290     status = NV_DONE_S;\r
1291   }\r
1292 \r
1293 #ifdef FEATURE_NV_CNV\r
1294   /* If the file was dropped in as part of a CEFS image, then restore\r
1295      the NV items */\r
1296   nvim_cnv_check();\r
1297 \r
1298   /* Remove the file since we are done updating the NV items and just\r
1299      in case the file is left hanging around because of error conditions */\r
1300   if (efs_unlink (cnv_file) < 0) {\r
1301     QSR_MSG_HIGH ( 2406613708ULL, "Unable to remove CNV file", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1302   }\r
1303 #endif\r
1304 \r
1305   (void)nverr_init();      /* cannot init err logging until nv is built */\r
1306   (void)nvim_init_rental_timer();  /* validate the rental timer item */\r
1307   (void)nvim_init_rental_cnt();    /* validate the rental count item */\r
1308 \r
1309 #if !defined( FEATURE_NV_RUIM ) || defined( FEATURE_UIM_RUN_TIME_ENABLE )\r
1310   nvim_init_prl_data();      /* initialize prl state data items */\r
1311 #endif /* FEATURE_RUIM */\r
1312 \r
1313 #ifdef FEATURE_DIAG_FS_ACCESS_VALIDATION\r
1314   nv_register_remote_access_check();\r
1315 #endif\r
1316 \r
1317   return status;\r
1318 } /* nv_init */\r
1319 \r
1320 #ifdef FEATURE_MDN_BASED_NAI\r
1321 \f\r
1322 /*===========================================================================\r
1323 \r
1324 FUNCTION NV_BCD_TO_CHAR\r
1325 \r
1326 DESCRIPTION\r
1327   Functions to convert MDN (BCD form) into ASCII characters.\r
1328 \r
1329 DEPENDENCIES\r
1330   None.\r
1331 \r
1332 RETURN VALUE\r
1333   Returns the characters for the numeric values between 1 - 9.\r
1334   Returns 0 for 10, * for 11 and # for 12.\r
1335 \r
1336 SIDE EFFECTS\r
1337   None.\r
1338 \r
1339 ===========================================================================*/\r
1340 char nv_bcd_to_char\r
1341 (\r
1342   word num_to_convert\r
1343 )\r
1344 {\r
1345   switch(num_to_convert)\r
1346   {\r
1347     case 1:\r
1348     case 2:\r
1349     case 3:\r
1350     case 4:\r
1351     case 5:\r
1352     case 6:\r
1353     case 7:\r
1354     case 8:\r
1355     case 9:\r
1356       return '0' + num_to_convert;\r
1357     case 10:\r
1358       return '0';\r
1359     case 11:\r
1360       return '*';\r
1361     case 12:\r
1362       return '#';\r
1363     default:\r
1364       QSR_MSG_ERROR ( 2574375817ULL, "Invalid BCD digit (%d)", num_to_convert, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1365       return ' ';\r
1366   }\r
1367 } /* nv_bcd_to_char */\r
1368 \r
1369 \f\r
1370 /*===========================================================================\r
1371 \r
1372 FUNCTION NV_NAI_FROM_MDN\r
1373 \r
1374 DESCRIPTION\r
1375   Functions form NAI based on given MDN and domain .\r
1376 \r
1377 DEPENDENCIES\r
1378   None.\r
1379 \r
1380 RETURN VALUE\r
1381   TRUE    if it worked\r
1382   FALSE   Failure\r
1383 \r
1384 SIDE EFFECTS\r
1385   None.\r
1386 \r
1387 ===========================================================================*/\r
1388 \r
1389 boolean nv_nai_from_mdn\r
1390 (\r
1391   char *                  nai_to_write,\r
1392   word *                  len,   //  len should be set to MAX_NAI_LENGTH\r
1393   nv_mob_dir_data_type *  mob_dir,\r
1394   char *                  domain  // must be null terminated\r
1395 )\r
1396 {\r
1397   int  i, cpylen;\r
1398 \r
1399   ASSERT (nai_to_write);\r
1400   ASSERT (len);\r
1401   ASSERT (mob_dir);\r
1402   ASSERT (domain);\r
1403 \r
1404   if (*len < mob_dir->n_digits + 1)\r
1405   {\r
1406     QSR_MSG_ERROR ( 2878414871ULL, "Output nai buffer too small for MDN",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1407     return FALSE;\r
1408   }\r
1409 \r
1410   for (i = 0; i < mob_dir->n_digits; i++)\r
1411   {\r
1412     nai_to_write[i] = nv_bcd_to_char(mob_dir->digitn[i]);\r
1413     if (nai_to_write[i] == ' ')\r
1414     {\r
1415       QSR_MSG_ERROR ( 3975514337ULL, "Invalid MDN when converting to NAI",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1416       return FALSE;  // item_to_be_written = FALSE;\r
1417     }\r
1418   }\r
1419 \r
1420   nai_to_write[i] = 0;\r
1421  \r
1422   cpylen = strlen(domain);\r
1423   if (cpylen > *len - i - 1)\r
1424   {\r
1425     QSR_MSG_ERROR ( 4243638384ULL, "Output nai buffer too small for domain",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1426     return FALSE;  // item_to_be_written = FALSE;\r
1427   }\r
1428 \r
1429   std_strlcat(&(nai_to_write[i]), domain, *len - i - 1);\r
1430   nai_to_write[i+cpylen] = 0;  // NULL terminate\r
1431   *len = i + cpylen;\r
1432   return TRUE;\r
1433 } /* nv_nai_from_mdn */\r
1434 \r
1435 /*===========================================================================\r
1436 \r
1437 FUNCTION NV_GET_DFLT_MIP_PROFILE\r
1438 \r
1439 DESCRIPTION\r
1440   Sets the current profile with the parameters for the default MIP profile.\r
1441 \r
1442 DEPENDENCIES\r
1443   None.\r
1444 \r
1445 RETURN VALUE\r
1446   None.\r
1447 \r
1448 SIDE EFFECTS\r
1449   None.\r
1450 \r
1451 ===========================================================================*/\r
1452 \r
1453 LOCAL void nv_get_dflt_mip_profile\r
1454 (\r
1455   nv_ds_mip_gen_user_prof_type * prof\r
1456 )\r
1457 {\r
1458   ASSERT (prof);\r
1459 \r
1460   prof->index             = MIP_DLFT_PROFILE_NUM;\r
1461   prof->nai_length        = 0;\r
1462   prof->nai[0]            = 0;\r
1463   prof->mn_ha_spi_set     = TRUE;\r
1464   prof->mn_ha_spi         = MIP_MD5_SPI;\r
1465   prof->mn_aaa_spi_set    = TRUE;\r
1466   prof->mn_aaa_spi        = MIP_CHAP_SPI;\r
1467   prof->rev_tun_pref      = FALSE;\r
1468   prof->home_addr         = DYNAMIC_HOME_ADDR;\r
1469   prof->primary_ha_addr   = DYNAMIC_HA_ADDR;\r
1470   prof->secondary_ha_addr = UNSET_HA_ADDR;\r
1471 } /* nv_get_dflt_mip_profile */\r
1472 #endif /* FEATURE_MDN_BASED_NAI */\r
1473 \r
1474 \r
1475 \f\r
1476 /*===========================================================================\r
1477 \r
1478 FUNCTION NV_OTASP_COMMIT\r
1479 \r
1480 DESCRIPTION\r
1481   This function performs the OTASP "commit" operation, which updates\r
1482   a number of OTASP-related nv items at once.  \r
1483 \r
1484 DEPENDENCIES\r
1485   None.\r
1486 \r
1487 RETURN VALUE\r
1488   NV_DONE_S    if it worked\r
1489   Others       Failure for internal call\r
1490 \r
1491 SIDE EFFECTS\r
1492   None.\r
1493 \r
1494 ===========================================================================*/\r
1495 \r
1496 LOCAL nv_stat_enum_type \r
1497 nv_otasp_commit (\r
1498   nv_cmd_ext_type  *cmd_ext_ptr          /* Command block */\r
1499 )\r
1500 {\r
1501   nv_cmd_ext_type local_cmd_ext;\r
1502 \r
1503 #ifdef FEATURE_NV_OTASP\r
1504 \r
1505 /* Define constants for the switch statement below */\r
1506 #define NV_COMMIT_DIR_NUM                      0\r
1507 #define NV_COMMIT_IMSI_ADDR                    1\r
1508 #define NV_COMMIT_IMSI_MCC                     2\r
1509 #define NV_COMMIT_IMSI_11_12                   3\r
1510 #define NV_COMMIT_MIN1                         4\r
1511 #define NV_COMMIT_MIN2                         5\r
1512 #define NV_COMMIT_ACCOLC                       6\r
1513 #define NV_COMMIT_MOB_HOME                     7\r
1514 #define NV_COMMIT_MOB_SID                      8\r
1515 #define NV_COMMIT_MOB_NID                      9\r
1516 #define NV_COMMIT_SID_NID                     10\r
1517 #define NV_COMMIT_FIRSTCHP                    11\r
1518 #define NV_COMMIT_HOME_SID                    12\r
1519 #define NV_COMMIT_ROAM_LIST                   13\r
1520 #define NV_COMMIT_SPC                         14\r
1521 #define NV_COMMIT_IMSI_T_S1                   15\r
1522 #define NV_COMMIT_IMSI_T_S2                   16\r
1523 #define NV_COMMIT_IMSI_T_11_12                17\r
1524 #define NV_COMMIT_IMSI_T_MCC                  18\r
1525 #define NV_COMMIT_IMSI_T_ADDR_NUM             19\r
1526 #define NV_COMMIT_NAM_LOCK                    20\r
1527 #define NV_COMMIT_PRIMARY_MIP_NAI_AFTER_MDN   21\r
1528 #define NV_COMMIT_PRIMARY_SIP_NAI_AFTER_MDN   22\r
1529 #define NV_COMMIT_AN_NAI_AFTER_MDN            23\r
1530 \r
1531 #define NV_COMMIT_DONE            255\r
1532 \r
1533   boolean      item_to_be_written; /* Flag controls whether write occurs */\r
1534   byte         i, commit_state=0;  /* Index variables */\r
1535 \r
1536 #ifdef FEATURE_MDN_BASED_NAI\r
1537 \r
1538 /* use the largest of the source nai fields (MIP, SIP, AN) */\r
1539 #define MAX_NAI_LENGTH NV_MAX_PPP_USER_ID_LENGTH\r
1540 \r
1541   char    nai_to_write[MAX_NAI_LENGTH]; // max for MIP, check SIP\r
1542   char    domain[MAX_NAI_LENGTH + 1];\r
1543   char *  domain_ptr;\r
1544   word    nai_length;\r
1545 #endif /* FEATURE_MDN_BASED_NAI */\r
1546 \r
1547   QSR_MSG_HIGH ( 771664511ULL, "NV Starting OTASP commit", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1548 \r
1549   /* Raise NV task priority for OTASP commit operation (and save */\r
1550   /* original priority so it can be restored at end of commit)   */\r
1551 \r
1552   QSR_MSG_HIGH ( 3779412989ULL, "NV Priority raised for OTASP", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1553   /* Set up generic command buffer parameters */\r
1554   local_cmd.cmd         = NV_WRITE_F;\r
1555   local_cmd.tcb_ptr     = NULL;\r
1556   local_cmd.sigs        = 0;\r
1557   local_cmd.done_q_ptr  = NULL;\r
1558   local_cmd.data_ptr    = &local_item;\r
1559   local_cmd.status      = NV_DONE_S;\r
1560 \r
1561   while (commit_state != NV_COMMIT_DONE) { \r
1562 \r
1563     item_to_be_written = FALSE;\r
1564     switch (commit_state) {\r
1565   \r
1566       case NV_COMMIT_DIR_NUM:\r
1567     \r
1568         /* Read control flag to determine if item should be written */\r
1569         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_mob_dir) {\r
1570 \r
1571           /* Write NV_DIR_NUMBER_PCS_I */\r
1572           item_to_be_written = TRUE;\r
1573           local_item.mob_dir_number.nam = \r
1574               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1575           local_item.mob_dir_number.n_digits = \r
1576               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->mob_dir.n_digits;\r
1577           for (i=0; i < NV_DIR_NUMB_PCS_SIZ; ++i) {\r
1578             local_item.mob_dir_number.digitn[i] = \r
1579                 cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->mob_dir.digitn[i];\r
1580           }      \r
1581           local_cmd.item = NV_DIR_NUMBER_PCS_I;\r
1582         }\r
1583 \r
1584         /* Set next state */\r
1585 #ifdef FEATURE_MDN_BASED_NAI\r
1586         if (item_to_be_written) \r
1587         {\r
1588           commit_state = NV_COMMIT_PRIMARY_MIP_NAI_AFTER_MDN;\r
1589           break;\r
1590         }\r
1591 #endif /* FEATURE_MDN_BASED_NAI */\r
1592         commit_state = NV_COMMIT_IMSI_ADDR;\r
1593         break;\r
1594 \r
1595       case NV_COMMIT_IMSI_ADDR:\r
1596 \r
1597         /* Read control flag to determine if items should be written */\r
1598         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_ftc_cdma) {\r
1599         \r
1600           /* Write NV_IMSI_ADDR_NUM_I */\r
1601           item_to_be_written = TRUE;\r
1602           local_item.imsi_addr_num.nam = \r
1603               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1604           local_item.imsi_addr_num.num = \r
1605               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_addr_num;\r
1606           local_cmd.item = NV_IMSI_ADDR_NUM_I;\r
1607           /* Set commit_state to write the additional items of this group */\r
1608           commit_state = NV_COMMIT_IMSI_MCC;\r
1609         }\r
1610         else {\r
1611           /* Control flag indicates no items from this group should */\r
1612           /* be written, so set commit_state to bypass them all     */\r
1613           commit_state = NV_COMMIT_FIRSTCHP;\r
1614         }\r
1615         break;\r
1616 \r
1617       case NV_COMMIT_IMSI_MCC:\r
1618 \r
1619         /* Write NV_IMSI_MCC_I */\r
1620         item_to_be_written = TRUE;\r
1621         local_item.imsi_mcc.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1622         local_item.imsi_mcc.imsi_mcc = \r
1623             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.mcc;\r
1624         local_cmd.item = NV_IMSI_MCC_I;\r
1625         /* Set commit_state to write the next item of this group */\r
1626         commit_state++;\r
1627         break;\r
1628 \r
1629       case NV_COMMIT_IMSI_11_12:\r
1630 \r
1631         /* Write NV_IMSI_11_12_I */\r
1632         item_to_be_written = TRUE;\r
1633         local_item.imsi_11_12.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1634         local_item.imsi_11_12.imsi_11_12 = \r
1635             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_11_12;\r
1636         local_cmd.item = NV_IMSI_11_12_I;\r
1637         /* Set commit_state to write the next item of this group */\r
1638         commit_state++;\r
1639         break;\r
1640 \r
1641       case NV_COMMIT_MIN1:\r
1642 \r
1643         /* Write NV_MIN1_I */\r
1644         item_to_be_written = TRUE;\r
1645         local_item.min1.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1646         local_item.min1.min1[NV_CDMA_MIN_INDEX] = \r
1647             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_s1;\r
1648         /* Set both the CDMA min and the analog min to this same value */\r
1649         local_item.min1.min1[NV_ANALOG_MIN_INDEX] = \r
1650             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_s1;\r
1651         local_cmd.item = NV_MIN1_I;\r
1652         /* Set commit_state to write the next item of this group */\r
1653         commit_state++;\r
1654         break;\r
1655 \r
1656       case NV_COMMIT_MIN2:\r
1657 \r
1658         /* Write NV_MIN2_I */\r
1659         item_to_be_written = TRUE;\r
1660         local_item.min2.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1661         local_item.min2.min2[NV_CDMA_MIN_INDEX] = \r
1662             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_s2;\r
1663         /* Set both the CDMA min and the analog min to this same value */\r
1664         local_item.min2.min2[NV_ANALOG_MIN_INDEX] = \r
1665             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.imsi_s2;\r
1666         local_cmd.item = NV_MIN2_I;\r
1667         /* Set commit_state to write the next item of this group */\r
1668         commit_state++;\r
1669         break;\r
1670 \r
1671       case NV_COMMIT_ACCOLC:\r
1672 \r
1673         /* Write NV_ACCOLC_I */\r
1674         item_to_be_written = TRUE;\r
1675         local_item.accolc.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1676         local_item.accolc.ACCOLCpClass[NV_CDMA_MIN_INDEX] = \r
1677             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.accolc;\r
1678         local_cmd.item = NV_ACCOLC_I;\r
1679         /* Set commit_state to write the next item of this group */\r
1680         commit_state++;\r
1681         break;\r
1682 \r
1683       case NV_COMMIT_MOB_HOME:\r
1684 \r
1685         /* Write NV_MOB_TERM_HOME_I */\r
1686         item_to_be_written = TRUE;\r
1687         local_item.mob_term_home.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1688         local_item.mob_term_home.enabled[NV_CDMA_MIN_INDEX] = \r
1689             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.mob_term_home;\r
1690         local_cmd.item = NV_MOB_TERM_HOME_I;\r
1691         /* Set commit_state to write the next item of this group */\r
1692         commit_state++;\r
1693         break;\r
1694 \r
1695       case NV_COMMIT_MOB_SID:\r
1696 \r
1697         /* Write NV_MOB_TERM_FOR_SID_I */\r
1698         item_to_be_written = TRUE;\r
1699         local_item.mob_term_for_sid.nam = \r
1700             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1701         local_item.mob_term_for_sid.enabled[NV_CDMA_MIN_INDEX] = \r
1702             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.mob_term_for_sid;\r
1703         local_cmd.item = NV_MOB_TERM_FOR_SID_I;\r
1704         /* Set commit_state to write the next item of this group */\r
1705         commit_state++;\r
1706         break;\r
1707 \r
1708       case NV_COMMIT_MOB_NID:\r
1709 \r
1710         /* Write NV_MOB_TERM_FOR_NID_I */\r
1711         item_to_be_written = TRUE;\r
1712         local_item.mob_term_for_nid.nam = \r
1713             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1714         local_item.mob_term_for_nid.enabled[NV_CDMA_MIN_INDEX] = \r
1715             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.mob_term_for_nid;\r
1716         local_cmd.item = NV_MOB_TERM_FOR_NID_I;\r
1717         /* Set commit_state to write the next item of this group */\r
1718         commit_state++;\r
1719         break;\r
1720 \r
1721       case NV_COMMIT_SID_NID:\r
1722 \r
1723         /* Write NV_SID_NID_I */\r
1724         item_to_be_written = TRUE;\r
1725         /* All the targets which have SSPR Enhancements use NV item HOME SID-NID */\r
1726 #if (defined (NV_FEATURE_SSPR_ENHANCEMENTS) || defined (NV_FEATURE_TRIMODE_ITEMS))\r
1727         local_item.home_sid_nid.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1728         for(i=0;i<NV_MAX_HOME_SID_NID;i++)\r
1729         {\r
1730           local_item.home_sid_nid.pair[i].sid = \r
1731               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.pair[i].sid;\r
1732           local_item.home_sid_nid.pair[i].nid = \r
1733               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.pair[i].nid;\r
1734         } \r
1735         local_cmd.item = NV_HOME_SID_NID_I;\r
1736 #else\r
1737         local_item.sid_nid.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1738         for(i=0;i<NV_MAX_SID_NID;i++)\r
1739         {\r
1740           local_item.sid_nid.pair[NV_CDMA_MIN_INDEX][i].sid = \r
1741               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.pair[i].sid;\r
1742           local_item.sid_nid.pair[NV_CDMA_MIN_INDEX][i].nid = \r
1743               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_cdma.pair[i].nid;\r
1744         }\r
1745         local_cmd.item = NV_SID_NID_I;\r
1746 #endif\r
1747         /* Set next state */\r
1748         commit_state = NV_COMMIT_FIRSTCHP;\r
1749         break;\r
1750 \r
1751       case NV_COMMIT_FIRSTCHP:\r
1752 \r
1753         /* Read control flag to determine if items should be written */\r
1754         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_ftc_amps) {\r
1755 \r
1756           /* Write NV_ANALOG_FIRSTCHP_I */\r
1757           item_to_be_written = TRUE;\r
1758           local_item.analog_firstchp.nam = \r
1759               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1760           local_item.analog_firstchp.channel = \r
1761               cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_amps.firstchp;\r
1762           local_cmd.item = NV_ANALOG_FIRSTCHP_I;\r
1763           /* Set commit_state to write the next item of this group */\r
1764           commit_state = NV_COMMIT_HOME_SID;\r
1765         }\r
1766         else {\r
1767           /* Control flag indicates no items from this group should */\r
1768           /* be written, so set commit_state to bypass them all     */\r
1769           commit_state = NV_COMMIT_SPC;\r
1770         }\r
1771         break;\r
1772 \r
1773       case NV_COMMIT_HOME_SID:\r
1774 \r
1775         /* Write NV_ANALOG_HOME_SID_I */\r
1776         item_to_be_written = TRUE;\r
1777         local_item.analog_home_sid.nam = \r
1778             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1779         local_item.analog_home_sid.sid = \r
1780             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->ftc_amps.home_sid;\r
1781         local_cmd.item = NV_ANALOG_HOME_SID_I;\r
1782         /* Set next state */\r
1783         commit_state = NV_COMMIT_SPC;\r
1784         break;\r
1785 \r
1786       case NV_COMMIT_SPC:\r
1787 \r
1788         /* Read control flag to determine if item should be written */\r
1789         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_spc) {\r
1790 \r
1791           /* Write NV_SEC_CODE_I */\r
1792           item_to_be_written = TRUE;\r
1793           local_item.sec_code = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->spc;\r
1794           local_cmd.item = NV_SEC_CODE_I;\r
1795         }\r
1796         /* Set next state */\r
1797         commit_state = NV_COMMIT_IMSI_T_S1;\r
1798         break;\r
1799 \r
1800       case NV_COMMIT_IMSI_T_S1:\r
1801 \r
1802         /* Read control flag to determine if items should be written */\r
1803         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_imsi_t) {\r
1804 \r
1805           /* Write NV_IMSI_T_S1 */\r
1806           item_to_be_written = TRUE;\r
1807           local_item.imsi_t_s1.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1808           local_item.imsi_t_s1.min1[NV_CDMA_MIN_INDEX] = \r
1809             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->imsi_t.s1;\r
1810           local_cmd.item = NV_IMSI_T_S1_I;\r
1811           /* Set commit_state to write the next item of this group */\r
1812           commit_state++;\r
1813         }\r
1814         else\r
1815         {\r
1816           /* Control flag indicates no items from this group should */\r
1817           /* be written, so set commit_state to bypass them all     */\r
1818           commit_state = NV_COMMIT_ROAM_LIST;\r
1819         }\r
1820         break;\r
1821 \r
1822       case NV_COMMIT_IMSI_T_S2:\r
1823 \r
1824         /* Write NV_IMSI_T_S2_I */\r
1825         item_to_be_written = TRUE;\r
1826         local_item.imsi_t_s2.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1827         local_item.imsi_t_s2.min2[NV_CDMA_MIN_INDEX] = \r
1828           cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->imsi_t.s2;\r
1829         local_cmd.item = NV_IMSI_T_S2_I;\r
1830         /* Set commit_state to write the next item of this group */\r
1831         commit_state++;\r
1832         break;\r
1833 \r
1834       case NV_COMMIT_IMSI_T_11_12:\r
1835 \r
1836         /* Write NV_IMSI_T_11_12_I */\r
1837         item_to_be_written = TRUE;\r
1838         local_item.imsi_t_11_12.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1839         local_item.imsi_t_11_12.imsi_11_12 = \r
1840           cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->imsi_t.imsi_t_11_12;\r
1841         local_cmd.item = NV_IMSI_T_11_12_I;\r
1842         /* Set commit_state to write the next item of this group */\r
1843         commit_state++;\r
1844         break;\r
1845       \r
1846       case NV_COMMIT_IMSI_T_MCC:\r
1847 \r
1848         /* Write NV_IMSI_T_MCC_I */\r
1849         item_to_be_written = TRUE;\r
1850         local_item.imsi_t_mcc.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1851         local_item.imsi_t_mcc.imsi_mcc = \r
1852           cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->imsi_t.mcc;\r
1853         local_cmd.item = NV_IMSI_T_MCC_I;\r
1854         /* Set commit_state to write the next item of this group */\r
1855         commit_state++;\r
1856         break;\r
1857 \r
1858       case NV_COMMIT_IMSI_T_ADDR_NUM:\r
1859 \r
1860         /* Write NV_IMSI_T_MCC_I */\r
1861         item_to_be_written = TRUE;\r
1862         local_item.imsi_t_addr_num.nam = \r
1863           cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1864         local_item.imsi_t_addr_num.num = \r
1865           cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->imsi_t.addr_num;\r
1866         local_cmd.item = NV_IMSI_T_ADDR_NUM_I;\r
1867         /* Set next state */\r
1868         commit_state = NV_COMMIT_ROAM_LIST;\r
1869         break;\r
1870 \r
1871       case NV_COMMIT_ROAM_LIST:\r
1872 \r
1873         /* Commit to the Roaming List MUST be the last commit to be performed  */\r
1874         /* This is, because the local_cmd.data_ptr gets assigned to pointer to */\r
1875         /* nv_pr_list during this sequence of operations. If one must add any  */\r
1876         /* other NV item in the commit switch after Roaming List at all, then  */\r
1877         /* (s)he should make sure to reassign this to local_item               */ \r
1878 \r
1879         /* Read control flag to determine if item should be written */\r
1880         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_roam_list) {\r
1881 \r
1882           /* Write NV_ROAMING_LIST_I */\r
1883           item_to_be_written = TRUE;\r
1884           local_cmd.data_ptr = (nv_item_type *)&nv_pr_list;\r
1885           #ifdef NV_FEATURE_IS683A_PRL\r
1886             local_cmd.item = NV_ROAMING_LIST_683_I;\r
1887           #else\r
1888             local_cmd.item = NV_ROAMING_LIST_I;\r
1889           #endif\r
1890         }\r
1891         /* Set next state */\r
1892         commit_state = NV_COMMIT_NAM_LOCK;\r
1893         break;\r
1894 \r
1895       case NV_COMMIT_NAM_LOCK:\r
1896         /* Read control flag to determine if items should be written */\r
1897         if (cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->commit_nam_lock) \r
1898         {\r
1899         #ifdef FEATURE_OTASP_OTAPA\r
1900           /* Write NV_NAM_LOCK_I */\r
1901           item_to_be_written = TRUE;\r
1902           local_item.nam_lock.nam = cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam;\r
1903           local_item.nam_lock.enabled = \r
1904             cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->nam_lock.enabled;\r
1905           local_cmd.item = NV_NAM_LOCK_I;\r
1906         #else\r
1907           ERR("Attempted to write NV_NAM_LOCK_I when FEATURE_OTASP_OTAPA not on",\r
1908               0, 0, 0);\r
1909         #endif\r
1910         }\r
1911         /* Set commit_state to signify we've finished committing */\r
1912         commit_state = NV_COMMIT_DONE;\r
1913       \r
1914         break;\r
1915 \r
1916 #ifdef FEATURE_MDN_BASED_NAI\r
1917       case NV_COMMIT_PRIMARY_MIP_NAI_AFTER_MDN:\r
1918 \r
1919         /*-------------------------------------------------------------------\r
1920           Note: this defaults to read/write profile at index 0.\r
1921                 Customer should use whichever index they assign\r
1922                 to the active MIP profile.\r
1923         -------------------------------------------------------------------*/\r
1924         local_item.ds_mip_gen_user_prof.index = MIP_DLFT_PROFILE_NUM;\r
1925         local_cmd.cmd                         = NV_READ_F;\r
1926         local_cmd.item                        = NV_DS_MIP_GEN_USER_PROF_I;\r
1927 \r
1928         local_cmd_ext.nvcmd = &local_cmd;\r
1929         local_cmd_ext.context = 0; /* No context is defined */\r
1930 \r
1931         local_cmd.status                      = nvio_read(&local_cmd_ext);\r
1932         if (local_cmd.status == NV_NOTACTIVE_S)\r
1933         {\r
1934           nv_get_dflt_mip_profile( &(local_item.ds_mip_gen_user_prof) );\r
1935         }\r
1936         else if (local_cmd.status != NV_DONE_S)\r
1937         {\r
1938           QSR_MSG_ERROR ( 1094358265ULL, "Error %d reading NV",local_cmd.status,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1939           commit_state = NV_COMMIT_PRIMARY_SIP_NAI_AFTER_MDN;\r
1940           break;\r
1941         }\r
1942 \r
1943         if(local_item.ds_mip_gen_user_prof.nai_length < NV_MAX_NAI_LENGTH)\r
1944           local_item.ds_mip_gen_user_prof.nai[\r
1945             local_item.ds_mip_gen_user_prof.nai_length] = 0;\r
1946         domain_ptr =\r
1947           std_strchr( (char*) local_item.ds_mip_gen_user_prof.nai, '@' );\r
1948         if (domain_ptr == NULL)\r
1949         {\r
1950           QSR_MSG_HIGH( 437141575ULL, "Using default domain",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1951           domain_ptr = PS_NAI_DFLT_DOMAIN;\r
1952         }\r
1953         std_strlcpy(domain,domain_ptr,NV_MAX_NAI_LENGTH);\r
1954         domain[NV_MAX_NAI_LENGTH] = 0;  // NULL terminate\r
1955 \r
1956         nai_length = NV_MAX_NAI_LENGTH;  // max bytes to write\r
1957         if( !nv_nai_from_mdn( nai_to_write,\r
1958                            &nai_length,\r
1959                            &(cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->mob_dir),\r
1960                            domain ) )\r
1961         {\r
1962           ERR("Couldn't convert MDN and domain to NAI!",0,0,0);\r
1963           commit_state = NV_COMMIT_PRIMARY_SIP_NAI_AFTER_MDN;\r
1964           break;\r
1965         }\r
1966 \r
1967         item_to_be_written = TRUE;\r
1968         local_cmd.cmd = NV_WRITE_F;\r
1969         local_item.ds_mip_gen_user_prof.nai_length = nai_length;\r
1970         memcpy( (char*) local_item.ds_mip_gen_user_prof.nai,\r
1971                 nai_to_write,\r
1972                 nai_length );\r
1973         commit_state = NV_COMMIT_PRIMARY_SIP_NAI_AFTER_MDN;\r
1974         break;\r
1975 \r
1976       case NV_COMMIT_PRIMARY_SIP_NAI_AFTER_MDN:\r
1977 \r
1978         local_cmd.cmd    = NV_READ_F;\r
1979         local_cmd.item   = NV_PPP_USER_ID_I;\r
1980 \r
1981         local_cmd_ext.nvcmd = &local_cmd;\r
1982         local_cmd_ext.context = 0; /* No context is defined */\r
1983 \r
1984         local_cmd.status = nvio_read(&local_cmd_ext);\r
1985         if (local_cmd.status == NV_NOTACTIVE_S)\r
1986         {\r
1987           local_item.ppp_user_id.user_id_len = 0;\r
1988         }\r
1989         else if (local_cmd.status != NV_DONE_S)\r
1990         {\r
1991           QSR_MSG_ERROR ( 1094358265ULL, "Error %d reading NV",local_cmd.status,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1992           commit_state = NV_COMMIT_AN_NAI_AFTER_MDN;\r
1993           break;\r
1994         }\r
1995 \r
1996         // copy the old domain from the user profile, or the default domain\r
1997         local_item.ppp_user_id.user_id[local_item.ppp_user_id.user_id_len] = 0;\r
1998         domain_ptr = std_strchr( (char*) local_item.ppp_user_id.user_id, '@' );\r
1999         if (domain_ptr == NULL)\r
2000         {\r
2001           QSR_MSG_HIGH( 1009080534ULL, "Using default domain for SIP nai",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
2002           domain_ptr = PS_NAI_DFLT_DOMAIN;\r
2003         }\r
2004         std_strlcpy(domain,domain_ptr,NV_MAX_PPP_USER_ID_LENGTH);\r
2005         domain[NV_MAX_PPP_USER_ID_LENGTH] = 0;  // NULL terminate\r
2006 \r
2007         nai_length = NV_MAX_PPP_USER_ID_LENGTH;  // max bytes to write\r
2008         if( !nv_nai_from_mdn( nai_to_write,\r
2009                            &nai_length,\r
2010                            &(cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->mob_dir),\r
2011                            domain ) )\r
2012         {\r
2013           ERR("Couldn't convert MDN and domain to NAI!",0,0,0);\r
2014           commit_state = NV_COMMIT_AN_NAI_AFTER_MDN;\r
2015           break;\r
2016         }\r
2017 \r
2018         item_to_be_written = TRUE;\r
2019         local_cmd.cmd      = NV_WRITE_F;\r
2020         local_cmd.item     = NV_PPP_USER_ID_I;\r
2021         local_item.ppp_user_id.user_id_len = nai_length;\r
2022         memcpy( (char*) local_item.ppp_user_id.user_id,\r
2023                 nai_to_write,\r
2024                 nai_length );\r
2025         commit_state = NV_COMMIT_AN_NAI_AFTER_MDN;\r
2026         break;\r
2027 \r
2028       case NV_COMMIT_AN_NAI_AFTER_MDN:\r
2029         \r
2030         local_cmd.cmd    = NV_READ_F;\r
2031         local_cmd.item   = NV_HDR_AN_AUTH_USER_ID_LONG_I;\r
2032 \r
2033         local_cmd_ext.nvcmd = &local_cmd;\r
2034         local_cmd_ext.context = 0; /* No context is defined */\r
2035 \r
2036         local_cmd.status = nvio_read(&local_cmd_ext);\r
2037         if (local_cmd.status == NV_NOTACTIVE_S)\r
2038         {\r
2039           local_item.hdr_an_ppp_user_id.user_id_len = 0;\r
2040         }\r
2041         else if (local_cmd.status != NV_DONE_S)\r
2042         {\r
2043           QSR_MSG_ERROR ( 1094358265ULL, "Error %d reading NV",local_cmd.status,0,0);//auto-gen, to change remove 'QSR_' and first param\r
2044           commit_state = NV_COMMIT_IMSI_ADDR;\r
2045           break;\r
2046         }\r
2047  \r
2048         // copy the old domain from the user profile, or the default domain\r
2049         local_item.hdr_an_ppp_user_id.user_id[\r
2050           local_item.hdr_an_ppp_user_id.user_id_len] = 0;\r
2051         domain_ptr =\r
2052           std_strchr( (char*) local_item.hdr_an_ppp_user_id.user_id, '@' );\r
2053         if (domain_ptr == NULL)\r
2054         {\r
2055           QSR_MSG_HIGH( 4198565724ULL, "Using default domain for AN nai",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
2056           domain_ptr = PS_NAI_DFLT_DOMAIN;\r
2057         }\r
2058         std_strlcpy(domain,domain_ptr,NV_MAX_AN_PPP_USER_ID_LENGTH);\r
2059         domain[NV_MAX_AN_PPP_USER_ID_LENGTH] = 0;  // NULL terminate\r
2060  \r
2061         nai_length = NV_MAX_AN_PPP_USER_ID_LENGTH;  // max bytes to write\r
2062         if( !nv_nai_from_mdn( nai_to_write,\r
2063                            &nai_length,\r
2064                            &(cmd_ext_ptr->nvcmd->data_ptr->otasp_commit->mob_dir),\r
2065                            domain ) )\r
2066         {\r
2067           ERR("Couldn't convert MDN and domain to NAI!",0,0,0);\r
2068           commit_state = NV_COMMIT_IMSI_ADDR;\r
2069           break;\r
2070         }\r
2071  \r
2072         item_to_be_written = TRUE;\r
2073         local_cmd.cmd      = NV_WRITE_F;\r
2074         local_cmd.item     = NV_HDR_AN_AUTH_USER_ID_LONG_I;\r
2075         local_item.hdr_an_ppp_user_id.user_id_len = nai_length;\r
2076         memcpy( (char*) local_item.hdr_an_ppp_user_id.user_id,\r
2077                 nai_to_write,\r
2078                 nai_length );\r
2079         commit_state = NV_COMMIT_IMSI_ADDR;\r
2080         break;\r
2081 #endif /* FEATURE_MDN_BASED_NAI */ \r
2082 \r
2083 \r
2084       default:\r
2085         /* Restore original NV task priority before returning */\r
2086  \r
2087         QSR_MSG_HIGH ( 3773457423ULL, "NV Priority Returned to NORMAL", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2088         return(cmd_ext_ptr->nvcmd->status = NV_BADCMD_S);\r
2089       \r
2090     } /* switch */\r
2091 \r
2092     if (item_to_be_written == TRUE) {\r
2093       local_cmd_ext.nvcmd = &local_cmd;\r
2094       local_cmd_ext.context = 0; /* No context is defined */\r
2095 \r
2096       local_cmd.status = nvio_write(&local_cmd_ext);\r
2097 \r
2098       if (local_cmd.status != NV_DONE_S) {\r
2099         /* Restore original NV task priority before returning */\r
2100        \r
2101         QSR_MSG_HIGH ( 3773457423ULL, "NV Priority Returned to NORMAL", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2102         return (local_cmd.status);\r
2103       }\r
2104     }\r
2105 \r
2106     /* Reset data_ptr for next item */\r
2107     local_cmd.data_ptr = &local_item;\r
2108   } /* while */  \r
2109 \r
2110   /* Restore original NV task priority before returning */\r
2111 \r
2112   QSR_MSG_HIGH ( 3773457423ULL, "NV Priority Returned to NORMAL", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2113   return (local_cmd.status);\r
2114 \r
2115 #else\r
2116   return NV_BADTG_S;\r
2117 \r
2118 #endif /* FEATURE_NV_OTASP */\r
2119 } /* nv_otasp_commit */\r
2120 \r
2121 \f\r
2122 /*===========================================================================\r
2123 \r
2124 FUNCTION NV_PRL_IS_VALID\r
2125 \r
2126 DESCRIPTION\r
2127   This function returns the "valid" indicator from the specified NAM's\r
2128   roaming list.  \r
2129 \r
2130 DEPENDENCIES\r
2131   None.\r
2132 \r
2133 RETURN VALUE\r
2134   TRUE         if the roaming list "valid" field is TRUE \r
2135   FALSE        if the roaming list "valid" field is FALSE or if the\r
2136                  specified NAM is invalid or if the roaming list\r
2137                  is currently NOT_ACTIVE\r
2138 \r
2139 SIDE EFFECTS\r
2140   None.  \r
2141   \r
2142 ===========================================================================*/\r
2143 \r
2144 boolean  nv_prl_is_valid\r
2145 (\r
2146   byte   nam          /* Which NAM the request is for */\r
2147 )\r
2148 {\r
2149   /* Check for illegal NAM */\r
2150   if (nam >= NV_MAX_NAMS) return FALSE;\r
2151 \r
2152   /* Note that valid field is set FALSE if prl is NOT_ACTIVE */\r
2153   return nv_prl_valid_data[nam];\r
2154 }\r
2155 \r
2156 \f\r
2157 /*===========================================================================\r
2158 \r
2159 FUNCTION NV_PRL_VERSION\r
2160 \r
2161 DESCRIPTION\r
2162   This function returns the "prl_version" indicator from the specified NAM's\r
2163   roaming list.  \r
2164 \r
2165 DEPENDENCIES\r
2166   None.\r
2167 \r
2168 RETURN VALUE\r
2169   prl_version             if the roaming list for the specified NAM is\r
2170                             currently ACTIVE \r
2171   NV_PRL_VERSION_INVALID  if the specified NAM is invalid or if the \r
2172                             roaming list for the specified NAM is \r
2173                             currently NOT_ACTIVE\r
2174 \r
2175 SIDE EFFECTS\r
2176   None.\r
2177 \r
2178 ===========================================================================*/\r
2179 \r
2180 word  nv_prl_version\r
2181 (\r
2182   byte   nam          /* Which NAM the request is for */\r
2183 )\r
2184 {\r
2185   /* Check for illegal NAM */\r
2186   if (nam >= NV_MAX_NAMS) return NV_PRL_VERSION_INVALID;\r
2187 \r
2188   /* Note that prl_version field is set to NV_PRL_VERSION_INVALID if   */\r
2189   /* the roaming list is NOT_ACTIVE                                    */\r
2190   return nv_prl_version_data[nam];\r
2191 }\r
2192 \r
2193 \f\r
2194 /*===========================================================================\r
2195 \r
2196 FUNCTION NVIMNV_TASK_START\r
2197 \r
2198 DESCRIPTION\r
2199   This function performs NV task initialization.  The function\r
2200   first sets the acknowledge signal back to MC to acknowledge that it has\r
2201   been created.  It then waits for the start signal back to it.  While\r
2202   waiting for the start signal and keeps kicking the watchdog timer\r
2203   everytime its interval timer has expired.  When it gets the start\r
2204   signal it then performs file initialization.\r
2205   Once initialization completes, it then  acknowledges it back to MC \r
2206   and returns to the caller.\r
2207 \r
2208 DEPENDENCIES\r
2209   None.\r
2210 \r
2211 RETURN VALUE\r
2212   None.\r
2213 \r
2214 SIDE EFFECTS\r
2215   The calling task stays here until it receives the START signal.\r
2216 \r
2217 ===========================================================================*/\r
2218 \r
2219 static void nvimnv_task_start\r
2220 (\r
2221   rex_sigs_type    rpt_sig,        /* report timer signal for task */\r
2222   dog_report_type  dog_rpt,        /* Watchdog report for the task */\r
2223   rex_timer_type   *rpt_timer_ptr  /* pointer to report timer */\r
2224 )\r
2225 {\r
2226 \r
2227   rex_sigs_type sigs;               /* Signals returned by rex_timed_wait. */\r
2228 \r
2229 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2230 \r
2231   /* Acknowledge task creation. */\r
2232 \r
2233   (void) rex_set_sigs(&tmc_tcb, TMC_ACK_SIG);\r
2234 \r
2235   /* Continue to set watchdog timer while waiting for start signal from MC. */\r
2236 \r
2237   for (;;)\r
2238   {\r
2239     /* Set a timed wait for OR of signals and a watchdog report timer. */\r
2240 \r
2241     sigs = rex_timed_wait(TASK_START_SIG | rpt_sig, rpt_timer_ptr, DOG_MC_RPT_TIME);\r
2242 \r
2243     /* If start signal is set then perform file initialization and  \r
2244        signal back to MC.     */\r
2245 \r
2246     if ((sigs & TASK_START_SIG) != 0)\r
2247     {\r
2248        (void) rex_clr_sigs(&nv_tcb, TASK_START_SIG);\r
2249        \r
2250        /* Initialize the EFS files. */\r
2251        if (nv_init() != NV_DONE_S) \r
2252        {\r
2253           ERR_FATAL("Failed NVIM EFS initialization", 0, 0, 0);\r
2254        }\r
2255        \r
2256        QSR_MSG_MED( 1502779829ULL, "NVIM initialization successfull", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2257        nvi_initialized = TRUE;\r
2258       \r
2259        nvdiag_init();\r
2260       \r
2261        /* Signal back to TMC acknowledgement.  */\r
2262        (void) rex_set_sigs(&tmc_tcb, TMC_ACK_SIG);\r
2263        break;\r
2264     }\r
2265     /* Otherwise timer has expired.  Kick the watchdog and loop.   */\r
2266     else\r
2267     {\r
2268        (void) rex_clr_sigs(&nv_tcb, rpt_sig);\r
2269        dog_report(dog_rpt);\r
2270     }\r
2271   } /* for */\r
2272 } /* nvimnv_task_start */\r
2273 \r
2274 \f\r
2275 /*===========================================================================\r
2276 \r
2277 FUNCTION NV_FRONT_OP\r
2278 \r
2279 DESCRIPTION\r
2280   This is the function called by both nv_cmd and nv_task. This is required\r
2281   in order to use kxmutexes for both synchronous and asynchronous accesses via\r
2282   NV.\r
2283 \r
2284 DEPENDENCIES\r
2285   The NV task must have been started up already.  All of the items in\r
2286   the nv_cmd_block must be already set.\r
2287 \r
2288 RETURN VALUE\r
2289   None directly.  The status variable of the nv_cmd_type will be updated\r
2290   to reflect the current status of this command as it is processed.\r
2291 \r
2292 SIDE EFFECTS\r
2293   The nv_cmd_type is placed on the NV command queue.  It must not be\r
2294   modified until the command has been processed.\r
2295 \r
2296 ===========================================================================*/\r
2297 \r
2298 \r
2299 void nv_front_op(\r
2300   nv_cmd_ext_type  *cmd_ext_ptr                   /* Pointer to NV command buffer */\r
2301   )\r
2302 {\r
2303   nv_cmd_type *cmd_ptr = cmd_ext_ptr->nvcmd;\r
2304   uint16 context = cmd_ext_ptr->context;\r
2305 \r
2306   if (context > MAX_NV_CONTEXT) {\r
2307     cmd_ptr->status = NV_FAIL_S;\r
2308     QSR_MSG_HIGH( 3451605573ULL, "NV context out of bounds", 0, 0, 0);    //auto-gen, to change remove 'QSR_' and first param\r
2309   }\r
2310   else {\r
2311 \r
2312   (void)KxMutex_Lock(&nv_access_op_cs);   \r
2313 \r
2314   switch (cmd_ptr->cmd) {\r
2315     case NV_READ_F:\r
2316         cmd_ptr->status = nvio_read(cmd_ext_ptr);\r
2317     break;\r
2318 \r
2319     case NV_WRITE_F:\r
2320         cmd_ptr->status = nvio_write(cmd_ext_ptr);\r
2321     break;\r
2322 \r
2323     case NV_PEEK_F:\r
2324       cmd_ptr->status = NV_FAIL_S;\r
2325     break;\r
2326 \r
2327     case NV_POKE_F:\r
2328       cmd_ptr->status = NV_FAIL_S;\r
2329     break;\r
2330 \r
2331     case NV_FREE_F:\r
2332         cmd_ptr->status = nvim_remove_item(cmd_ext_ptr);\r
2333     break;\r
2334 \r
2335     case NV_CHKPNT_ENA_F:\r
2336       break;\r
2337 \r
2338     case NV_CHKPNT_DIS_F:\r
2339       break;\r
2340 \r
2341     case NV_OTASP_COMMIT_F:\r
2342         cmd_ptr->status = nv_otasp_commit(cmd_ext_ptr);\r
2343     break;\r
2344 \r
2345     case NV_REPLACE_F:\r
2346         cmd_ptr->status = nvio_write(cmd_ext_ptr);\r
2347     break;\r
2348 \r
2349     case NV_INCREMENT_F:\r
2350         cmd_ptr->status = nvim_increment(cmd_ext_ptr);\r
2351     break;\r
2352            \r
2353 #ifdef FEATURE_UIM_RUN_TIME_ENABLE\r
2354     case NV_RTRE_OP_CONFIG_F:\r
2355         /* The function nvruim_process_rtre_configuration doesnot have any\r
2356            dependency on context. However creating new function to take input\r
2357            parameter cmd_ext_ptr */\r
2358       cmd_ptr->status = \r
2359         (nv_stat_enum_type)nvruim_process_rtre_configuration(cmd_ext_ptr->nvcmd, \r
2360                                         &nv_rtre_control_value,\r
2361                                         &nv_rtre_polling_control_value);\r
2362     break;\r
2363 #endif           \r
2364 \r
2365     default:\r
2366       cmd_ptr->status = NV_BADCMD_S;\r
2367     break;\r
2368 \r
2369   }/*switch*/\r
2370 \r
2371   (void)KxMutex_Unlock(&nv_access_op_cs);\r
2372 }\r
2373 \r
2374   /* Free memory allocated for cmd_ext_ptr */\r
2375   free(cmd_ext_ptr);\r
2376 \r
2377 } /* nv_front_op_ext */\r
2378 \r
2379 \f\r
2380 /*===========================================================================\r
2381 \r
2382 FUNCTION NV_TASK\r
2383 \r
2384 DESCRIPTION\r
2385   This is the NV task, created via rex_def_task from the Main Control task.\r
2386   The NV task sets MC_ACK_SIG when it is done with initialization and it\r
2387   then waits for NV_START_SIG before starting its normal operations.  The\r
2388   NV task then enters a main loop, awaiting for commands received on its\r
2389   input queue.  Each command received is processed and the loop continues.\r
2390   While in the main loop the task kicks the watchdog periodically.\r
2391 \r
2392   *MODIFIED to handle new parameter nv_cmd_ext_type\r
2393 \r
2394 DEPENDENCIES\r
2395   None.\r
2396 \r
2397 RETURN VALUE\r
2398   None.\r
2399 \r
2400 SIDE EFFECTS\r
2401   None.\r
2402 \r
2403 ===========================================================================*/\r
2404 \r
2405 void  nv_task\r
2406\r
2407   dword   parm          /* from REX - ignored */\r
2408 )\r
2409 {\r
2410   nv_cmd_ext_type     *cmd_ext_ptr;   /* Pointer to command received on nv_cmd_q */\r
2411   nv_cmd_type     *cmd_ptr;\r
2412   rex_sigs_type   rex_sigs;   /* REX signals word */\r
2413   rex_tcb_type    *task_ptr;  /* Task to signal back on request completion. */\r
2414   rex_sigs_type   task_sigs;  /* Signals to set back to requesting task */\r
2415 \r
2416 /*-------------------------------------------------------------------------*/\r
2417 \r
2418 /* Keep Lint happy */\r
2419 \r
2420 #ifdef _lint\r
2421   parm = parm;\r
2422 #endif\r
2423 \r
2424   QSR_MSG_MED( 3850502563ULL, "NV task created", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2425   \r
2426   /* Initialize the watchdog report timer and NV write timer. */\r
2427 \r
2428   rex_def_timer(&nv_rpt_timer,  &nv_tcb, NV_RPT_TIMER_SIG);\r
2429 \r
2430 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2431 \r
2432   /* Initialize the NV command queue. */\r
2433   (void) q_init(&nv_cmd_q);\r
2434 \r
2435 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2436 \r
2437 \r
2438   /* Wait for start signal. */\r
2439 \r
2440   nvimnv_task_start (NV_RPT_TIMER_SIG, DOG_NV_RPT, &nv_rpt_timer);\r
2441 \r
2442 \r
2443 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2444   /* Kick the wathcdog and start task operations. */\r
2445 \r
2446   KICK_WATCHDOG();\r
2447 \r
2448   /* signal nv err log operations to queue writes to nv */\r
2449   nvi_task_running = TRUE;   \r
2450 \r
2451   for (;;) { /*  while (TRUE) and Lint happy */\r
2452 \r
2453 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2454 \r
2455     /* Set REX wait with mask of all possible input signals. */\r
2456 \r
2457     rex_sigs = rex_wait(  NV_RPT_TIMER_SIG      /* Watchdog timer elapsed */\r
2458                         | NV_CMD_Q_SIG          /* Input of command queue */\r
2459                         | NV_ERR_LOG_SIG        /* Process the nverr record */\r
2460                         | TASK_STOP_SIG         /* Stop the NV task */\r
2461                         | TASK_OFFLINE_SIG);    /* Go offline */\r
2462 \r
2463 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2464 \r
2465     /* Kick watchdog and start the watchdog report timer.   */\r
2466     /* Note that the watchdog is kicked after every wakeup, */\r
2467     /* following input of any signal to the NV task.        */\r
2468 \r
2469     KICK_WATCHDOG();\r
2470 \r
2471 \f\r
2472 /*-------------------------------------------------------------------------*/\r
2473 /*                                                                         */\r
2474 /*                         COMMAND QUEUE SIGNAL                            */\r
2475 /*                                                                         */\r
2476 /*-------------------------------------------------------------------------*/\r
2477 \r
2478     if ((rex_sigs & NV_RPT_TIMER_SIG) != 0) {\r
2479       QSR_MSG_LOW( 252695986ULL, "NV_RPT_TIMER_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2480       /* write out any old ERR() if required */\r
2481       nverr_update_log();\r
2482     }\r
2483 \r
2484     if ((rex_sigs & NV_ERR_LOG_SIG) != 0) {\r
2485       QSR_MSG_LOW( 180449550ULL, "NV_ERR_LOG_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2486       (void) rex_clr_sigs(&nv_tcb, NV_ERR_LOG_SIG);\r
2487       /* write out any old ERR() if required */\r
2488       nverr_update_log();\r
2489     }\r
2490     /* Check if command queue signal was set. */\r
2491     /* If set then clear signal and proceeed. */\r
2492 \r
2493     if ((rex_sigs & NV_CMD_Q_SIG) != 0) {\r
2494       QSR_MSG_LOW( 3275661280ULL, "NV_CMD_Q_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2495       (void) rex_clr_sigs(&nv_tcb, NV_CMD_Q_SIG);\r
2496 \r
2497 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2498       /* Enter a loop where the command queue is checked and */\r
2499       while ((cmd_ext_ptr = (nv_cmd_ext_type *) q_get(&nv_cmd_q)) != NULL) \r
2500       {\r
2501         cmd_ptr = cmd_ext_ptr->nvcmd;\r
2502 \r
2503         nv_front_op(cmd_ext_ptr);  \r
2504 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2505 \r
2506         /* Save for a moment the requesting task TCB and signal to set. */\r
2507   \r
2508         task_ptr = cmd_ptr->tcb_ptr;\r
2509         task_sigs = cmd_ptr->sigs;\r
2510 \r
2511 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2512         \r
2513         /* If specified in request then return buffer to specified queue. */\r
2514 \r
2515         if (cmd_ptr->done_q_ptr != NULL)\r
2516           q_put(cmd_ptr->done_q_ptr, &cmd_ptr->link);\r
2517   \r
2518         /* If specified in request then signal the requesting task. */\r
2519   \r
2520         if (task_ptr != NULL)\r
2521           (void) rex_set_sigs(task_ptr, task_sigs);\r
2522   \r
2523         /* At the end of the loop kick the watchdog timer. */\r
2524   \r
2525         KICK_WATCHDOG();\r
2526   \r
2527       } /* while */\r
2528     } /* if command queue signal */\r
2529 \r
2530 /*-------------------------------------------------------------------------*/\r
2531 /*                                                                         */\r
2532 /*                       OFFLINE COMMAND SIGNAL                            */\r
2533 /*                                                                         */\r
2534 /*-------------------------------------------------------------------------*/\r
2535 \r
2536     /* Check if offline command signal was set. If set then clear signal, */\r
2537     /* send ack back to MC, and proceeed.                                 */\r
2538 \r
2539     if ((rex_sigs & TASK_OFFLINE_SIG) != 0) {\r
2540       QSR_MSG_MED( 1000812593ULL, "TASK_OFFLINE_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2541       (void) rex_clr_sigs(&nv_tcb, TASK_OFFLINE_SIG);\r
2542       (void) rex_set_sigs(&tmc_tcb, TMC_ACK_SIG);\r
2543       /* write out any old ERR() if required */\r
2544       nverr_update_log();\r
2545     } /* if offline command signal */\r
2546 \r
2547 /*-------------------------------------------------------------------------*/\r
2548 /*                                                                         */\r
2549 /*                     POWERDOWN (STOP) COMMAND SIGNAL                     */\r
2550 /*                                                                         */\r
2551 /*-------------------------------------------------------------------------*/\r
2552 \r
2553     /* Check if powerdown command signal was set. */\r
2554     /* If set then clear signal and proceeed.     */\r
2555 \r
2556     if ((rex_sigs & TASK_STOP_SIG) != 0) {\r
2557       /* write out any old ERR() if required */\r
2558       nverr_update_log();\r
2559       QSR_MSG_MED( 2124372139ULL, "TASK_STOP_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2560       (void) rex_clr_sigs(&nv_tcb, TASK_STOP_SIG);\r
2561 \r
2562       nvi_task_running=FALSE;\r
2563 \r
2564       task_stop ();\r
2565       /* Send ack back to MC. */\r
2566       /* (void) rex_set_sigs(&tmc_tcb, TMC_ACK_SIG); */\r
2567     } /* if stop command signal */\r
2568 \r
2569 /*-------------------------------------------------------------------------*/\r
2570 /*                                                                         */\r
2571 /*                     WATCHDOG REPORT TIMER SIGNAL                        */\r
2572 /*                                                                         */\r
2573 /*-------------------------------------------------------------------------*/\r
2574 \r
2575 /* PC debug only.                                                          */\r
2576 \r
2577 #ifdef FEATURE_NV_UNIT_TEST\r
2578     if ((rex_sigs & NV_RPT_TIMER_SIG) != 0) {\r
2579       (void) rex_clr_sigs(&nv_tcb, NV_RPT_TIMER_SIG);\r
2580       QSR_MSG_LOW( 252695986ULL, "NV_RPT_TIMER_SIG received", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2581     }\r
2582 #endif\r
2583 \r
2584 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2585   } /* for (;;) */\r
2586 } /* nv_task */\r
2587 \r
2588 \r
2589 \f\r
2590 /*===========================================================================\r
2591 FUNCTION NVERR_INIT\r
2592 \r
2593 DESCRIPTION\r
2594   Initialize nv error queue for external tasks\r
2595   \r
2596 DEPENDENCIES\r
2597   Called once, by NV.C to init buffers\r
2598 \r
2599 RETURN VALUE\r
2600   False if init conflict.\r
2601 \r
2602 SIDE EFFECTS\r
2603   None.\r
2604 \r
2605 ===========================================================================*/\r
2606 boolean \r
2607 nverr_init( void ) {\r
2608   int i;\r
2609   static boolean nv_error_initialized = FALSE;\r
2610   static boolean nv_error_init_in_progress = FALSE;\r
2611 \r
2612   /* We have allready visited this routine */\r
2613   if(nv_error_initialized) {\r
2614     nv_error_init_in_progress = FALSE;\r
2615     return TRUE;\r
2616   }\r
2617 \r
2618   /* Flag incase multiple paths initing nv at same time. */\r
2619   if(nv_error_init_in_progress) return FALSE;\r
2620   nv_error_init_in_progress = TRUE;\r
2621 \r
2622   /* read up shadow copy of error log */\r
2623   for(i=0; i< NV_MAX_ERR_LOG; i++) {\r
2624     (void) nvio_read_item (\r
2625         NV_ERR_LOG_I,\r
2626         (byte) i,                          /* Item index within its array */\r
2627         (byte*)&(nverr_log.external[i].err_count),          /* data buffer */\r
2628         nvim_op_get_size(NV_ERR_LOG_I),\r
2629         0 /* context=0 implies no context is defined */\r
2630     );\r
2631     nverr_log.update_required[i] = FALSE;\r
2632   }\r
2633   nverr_log.processing_required = FALSE;\r
2634 \r
2635   nv_error_initialized = TRUE;\r
2636   nv_error_init_in_progress = FALSE;\r
2637   return TRUE;\r
2638 }\r
2639 \r
2640 \f\r
2641 /*===========================================================================\r
2642 FUNCTION NVERR_UPDATE_LOG\r
2643 \r
2644 DESCRIPTION\r
2645   write dirty error log items out to nv.\r
2646   \r
2647 DEPENDENCIES\r
2648   nverr_init must have been called.\r
2649 \r
2650 RETURN VALUE\r
2651   None.\r
2652 \r
2653 SIDE EFFECTS\r
2654   None.\r
2655 \r
2656 ===========================================================================*/\r
2657 void \r
2658 nverr_update_log( void ) {\r
2659   int  i;      /* loop counter */\r
2660   word isave;  /* save flags for interrupt diasble/enable */\r
2661 \r
2662   /* If no errors waiting to be saved, get out of here */\r
2663   if(!nverr_log.processing_required) return;\r
2664 \r
2665   KICK_WATCHDOG();\r
2666 \r
2667   /* update internal copy of err_log to write out from */\r
2668   INTLOCK_SAV( isave );         /* Disable interrupts and save PSW */\r
2669   (void) memcpy((void *) nverr_log.internal,\r
2670          (void *) nverr_log.external, \r
2671          sizeof(nverr_log.internal));   /* data buffer size */\r
2672 \r
2673   (void) memcpy((void *) nverr_log.update_in_progress,\r
2674          (void *) nverr_log.update_required, \r
2675          sizeof(nverr_log.update_in_progress));   /* data buffer size */\r
2676 \r
2677   for(i=0; i< NV_MAX_ERR_LOG; i++) {\r
2678     nverr_log.update_required[i] = FALSE;\r
2679   }\r
2680   nverr_log.processing_required = FALSE;\r
2681   INTFREE_SAV( isave );         /* Restore interrupts (PSW) */\r
2682 \r
2683   /* write out internal shadow copy of error log */\r
2684   for(i=0; i< NV_MAX_ERR_LOG; i++) {\r
2685     if(nverr_log.update_in_progress[i]) {\r
2686       QSR_MSG_MED( 427085943ULL, "nverr_log entry %d update in progress ", i, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2687       KICK_WATCHDOG();\r
2688       nvio_write_item\r
2689              (\r
2690                  NV_ERR_LOG_I,\r
2691                  (byte) i,                          /* Item index within its array */\r
2692                  (byte *)&(nverr_log.internal[i].err_count),    /* data buffer */ \r
2693                  nvim_op_get_size(NV_ERR_LOG_I),\r
2694                  0 /* context=0 implies no context is defined */\r
2695              );\r
2696     }\r
2697   }\r
2698 }\r
2699 \r
2700 \f\r
2701 /*===========================================================================\r
2702 \r
2703 FUNCTION NV_MAX_SIZE_OF_ROAMING_LIST\r
2704 \r
2705 DESCRIPTION\r
2706   This function returns the maximum number of bytes available for\r
2707   storage of a roaming list (per NAM).  The value returned depends \r
2708   on the total amount of NVRAM installed in the phone and the total \r
2709   number of NAMs defined.  \r
2710 \r
2711 DEPENDENCIES\r
2712   The function cannot be called until NV is initialized.  A\r
2713   premature call will raise err_fatal.\r
2714 \r
2715 RETURN VALUE\r
2716   The maximum number of bytes available for storage of a roaming list\r
2717   (per NAM).\r
2718 \r
2719 SIDE EFFECTS\r
2720   None.\r
2721 \r
2722 ===========================================================================*/\r
2723 \r
2724 word  \r
2725 nv_max_size_of_roaming_list( void ) {\r
2726   if (!nvi_initialized)\r
2727   {\r
2728     ERR_FATAL("Illegal task start-up order", 0, 0, 0);\r
2729   }\r
2730 \r
2731   #if !defined( FEATURE_NV_RUIM ) || defined( FEATURE_UIM_RUN_TIME_ENABLE )\r
2732   #if defined( FEATURE_UIM_RUN_TIME_ENABLE )\r
2733     /* Determine if the R-UIM is available */\r
2734     if (NV_RTRE_CONTROL_USE_RUIM != nv_rtre_control())\r
2735   #endif /* FEATURE_UIM_RUN_TIME_ENABLE */\r
2736     {\r
2737     #ifdef NV_FEATURE_PRL_ITEMS\r
2738        return NV_ROAMING_LIST_MAX_SIZE;\r
2739     #else\r
2740        return (word)0;\r
2741     #endif\r
2742     }\r
2743   #if defined( FEATURE_UIM_RUN_TIME_ENABLE )\r
2744     else {\r
2745       #if defined( FEATURE_NVRUIM_ADM_ACCESS ) || defined( FEATURE_BUILD_JCDMA )\r
2746       /* Return a max number here and check the size in nvruim before writing */\r
2747         return NV_ROAMING_LIST_MAX_SIZE;\r
2748       #else\r
2749         return (word)0;\r
2750       #endif  /* FEATURE_RUIM_ADM_ACCESS */\r
2751     }\r
2752   #endif /*( FEATURE_UIM_RUN_TIME_ENABLE ) */\r
2753 \r
2754   #else\r
2755     return (word)0;\r
2756   #endif /* !FEATURE_NV_RUIM || FEATURE_UIM_RUN_TIME_ENABLE */\r
2757 \r
2758 } /* nv_max_size_of_roaming_list */\r
2759 \r
2760 \f\r
2761 /*===========================================================================\r
2762 \r
2763 FUNCTION NV_MAX_SIZE_OF_WEB_CACHE\r
2764 \r
2765 DESCRIPTION\r
2766   This function returns the maximum number of bytes currently available \r
2767   for storage of the Unwired Planet cache.  At this time, the cache\r
2768   size is always zero (it is not currently used).\r
2769   \r
2770 DEPENDENCIES\r
2771   The function cannot be called until NV is initialized.  A\r
2772   premature call will raise err_fatal.\r
2773 \r
2774 RETURN VALUE\r
2775   The maximum number of bytes currently available for storage of the\r
2776   Unwired Planet cache.\r
2777 \r
2778 SIDE EFFECTS\r
2779   None.\r
2780 \r
2781 ===========================================================================*/\r
2782 \r
2783 word  \r
2784 nv_max_size_of_web_cache( void ) {\r
2785   if (!nvi_initialized) {\r
2786     ERR_FATAL("Illegal task start-up order", 0, 0, 0);\r
2787   }\r
2788   return (word)0;\r
2789 } /* nv_max_size_of_web_cache */\r
2790 \r
2791 \f\r
2792 /*===========================================================================\r
2793 \r
2794 FUNCTION NV_BUILT\r
2795 \r
2796 DESCRIPTION\r
2797   This function will return TRUE once the files are available that simulate\r
2798   NV storage.\r
2799 \r
2800 DEPENDENCIES\r
2801   This is a special use function, normally called by error services\r
2802   to allow early access to NV, and before the NV task has been started.\r
2803   The NV Item Manager allows access once file initialization is complete.\r
2804 \r
2805 RETURN VALUE\r
2806   TRUE      - The NV has been built and direct read/write is allowed\r
2807   FALSE     - The NV has not been built and access is not allowed\r
2808 \r
2809 SIDE EFFECTS\r
2810   None.\r
2811 \r
2812 ===========================================================================*/\r
2813 \r
2814 boolean nv_built (void)\r
2815 \r
2816 {\r
2817   return nvi_initialized;\r
2818   \r
2819 } /* nv_built */\r
2820 \r
2821 \f\r
2822 /*===========================================================================\r
2823 \r
2824 FUNCTION NV_CMD\r
2825 \r
2826 DESCRIPTION\r
2827   This is the outside world's interface to the non volatile memory task\r
2828   this function takes an already filled out nv_cmd_type and place it on\r
2829   the nv queue.  The function returns to the caller after setting the\r
2830   status to busy indicaton.  This does _not_ mean that the command has\r
2831   been executed yet, just that it is waiting to be executed.\r
2832 \r
2833 DEPENDENCIES\r
2834   The NV task must have been started up already.  All of the items in\r
2835   the nv_cmd_block must be already set.\r
2836 \r
2837 RETURN VALUE\r
2838   None directly.  The status variable of the nv_cmd_type will be updated\r
2839   to reflect the current status of this command as it is processed.\r
2840 \r
2841 SIDE EFFECTS\r
2842   The nv_cmd_type is placed on the NV command queue.  It must not be\r
2843   modified until the command has been processed.\r
2844 \r
2845 ===========================================================================*/\r
2846 \r
2847 void  \r
2848 nv_cmd (\r
2849   nv_cmd_type  *cmd_ptr                   /* Pointer to NV command buffer */\r
2850 )\r
2851 {\r
2852 \r
2853   nv_cmd_ext_type *cmd_ext_ptr = (nv_cmd_ext_type *) malloc (sizeof(nv_cmd_ext_type));\r
2854 \r
2855   if (cmd_ext_ptr != NULL)\r
2856   { \r
2857 \r
2858     /* Converting nv_cmd_type to nv_cmd_ext_type by setting context to 0 */\r
2859     cmd_ext_ptr->nvcmd = cmd_ptr;\r
2860     cmd_ext_ptr->context = 0;\r
2861     \r
2862   /* Set the request status to busy. initialize and link the command  */\r
2863   /* onto the NV command queue, set a signal to the NV task and exit. */\r
2864     if (cmd_ext_ptr->nvcmd->tcb_ptr != NULL) \r
2865   {\r
2866       cmd_ext_ptr->nvcmd->status = NV_BUSY_S;\r
2867       (void) q_link(cmd_ext_ptr, &cmd_ext_ptr->link);\r
2868       q_put(&nv_cmd_q, &cmd_ext_ptr->link);\r
2869     (void) rex_set_sigs(&nv_tcb, NV_CMD_Q_SIG);\r
2870   }\r
2871     \r
2872   else\r
2873   {\r
2874 \r
2875     /* For synchronous calls, we need to ensure mutexes are initiliazed */\r
2876     if(!nv_cs_init_flag)\r
2877       nv_access_op_cs_init();\r
2878   \r
2879       nv_front_op(cmd_ext_ptr);\r
2880   } /* if command has no tcb  */\r
2881   }\r
2882   else \r
2883     QSR_MSG_HIGH ( 3639666217ULL, "Could not allocate memory for variable of type nv_cmd_ext_type", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2884   \r
2885 } /* nv_cmd */\r
2886 \r
2887 \r
2888 /*===========================================================================\r
2889 \r
2890 FUNCTION NV_CMD_EXT\r
2891 \r
2892 DESCRIPTION\r
2893   This is the outside world's interface to the non volatile memory task\r
2894   this function takes an already filled out nv_cmd_type and place it on\r
2895   the nv queue.  The function returns to the caller after setting the\r
2896   status to busy indicaton.  This does _not_ mean that the command has\r
2897   been executed yet, just that it is waiting to be executed.\r
2898 \r
2899 DEPENDENCIES\r
2900   The NV task must have been started up already.  All of the items in\r
2901   the nv_cmd_block must be already set. This function allows items across\r
2902   multiple SIMs to be accessed.\r
2903 \r
2904 RETURN VALUE\r
2905   None directly.  The status variable of the nv_cmd_ext_type will be updated\r
2906   to reflect the current status of this command as it is processed.\r
2907 \r
2908 SIDE EFFECTS\r
2909   The nv_cmd_ext_type is placed on the NV command queue.  It must not be\r
2910   modified until the command has been processed.\r
2911 \r
2912 ===========================================================================*/\r
2913 \r
2914 void  \r
2915 nv_cmd_ext (\r
2916   nv_cmd_ext_type  *cmd_ext_ptr                   /* Pointer to NV command buffer */\r
2917 )\r
2918 {\r
2919   nv_cmd_ext_type *lcmd_ext_ptr = (nv_cmd_ext_type *) malloc (sizeof(nv_cmd_ext_type));\r
2920 \r
2921   if (lcmd_ext_ptr != NULL)\r
2922   { \r
2923     /* copy the parameters into the allocated momory */\r
2924     lcmd_ext_ptr->nvcmd = cmd_ext_ptr->nvcmd;\r
2925     lcmd_ext_ptr->context = cmd_ext_ptr->context;\r
2926   } else {\r
2927     QSR_MSG_HIGH ( 3639666217ULL, "Could not allocate memory for variable of type nv_cmd_ext_type", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2928     return;\r
2929   }\r
2930 \r
2931   /* Set the request status to busy. initialize and link the command  */\r
2932   /* onto the NV command queue, set a signal to the NV task and exit. */\r
2933   if (lcmd_ext_ptr->nvcmd->tcb_ptr != NULL) \r
2934   {\r
2935     lcmd_ext_ptr->nvcmd->status = NV_BUSY_S;\r
2936     (void) q_link(lcmd_ext_ptr, &lcmd_ext_ptr->link);\r
2937     q_put(&nv_cmd_q, &lcmd_ext_ptr->link);\r
2938     (void) rex_set_sigs(&nv_tcb, NV_CMD_Q_SIG);\r
2939   }\r
2940   else\r
2941   {\r
2942 \r
2943     /* For synchronous calls, we need to ensure mutexes are initiliazed */\r
2944     if(!nv_cs_init_flag)\r
2945       nv_access_op_cs_init();\r
2946   \r
2947     nv_front_op(lcmd_ext_ptr);\r
2948   } /* if command has no tcb  */\r
2949 } /* nv_cmd_ext */\r
2950 \r
2951 \r
2952 \r
2953 /*===========================================================================\r
2954 \r
2955 FUNCTION NV_CMD_R\r
2956 \r
2957 DESCRIPTION\r
2958   This is same as nv_cmd but it waits till NV finishes its operation.\r
2959 \r
2960 DEPENDENCIES\r
2961   The NV task must have been started up already.  All of the items in\r
2962   the nv_cmd_block must be already set.\r
2963 \r
2964 RETURN VALUE\r
2965   None directly.  The status variable of the nv_cmd_type will be updated\r
2966   to reflect the current status of this command as it is processed.\r
2967 \r
2968 SIDE EFFECTS\r
2969   None.\r
2970 \r
2971 ===========================================================================*/\r
2972 \r
2973 void  \r
2974 nv_cmd_r (\r
2975   nv_cmd_type  *cmd_ptr,                   /* Pointer to NV command buffer */\r
2976   nv_item_type *data_ptr /* Pointer to structure that contains item data */\r
2977 )\r
2978 {\r
2979 #ifdef FEATURE_RPC\r
2980   nv_cmd_ext_type *cmd_ext_ptr = (nv_cmd_ext_type *) malloc (sizeof(nv_cmd_ext_type));\r
2981   \r
2982   /* Save params */\r
2983   rex_tcb_type *client_tcb = cmd_ptr->tcb_ptr;\r
2984   nv_item_type *client_data = cmd_ptr->data_ptr;\r
2985 \r
2986   /* Set the request status to busy. initialize and link the command  */\r
2987   /* onto the NV command queue, set a signal to the NV task and exit. */\r
2988 \r
2989   cmd_ptr->tcb_ptr = rex_self();\r
2990   cmd_ptr->data_ptr = data_ptr;\r
2991 \r
2992   cmd_ptr->status = NV_BUSY_S;\r
2993 \r
2994   /* Converting nv_cmd_type to nv_cmd_ext_type by setting context to 0 */\r
2995   if (cmd_ext_ptr != NULL) \r
2996   {\r
2997     cmd_ext_ptr->nvcmd = cmd_ptr;\r
2998     cmd_ext_ptr->context = 0;\r
2999     \r
3000     /* Putting nv_cmd_ext on queue */\r
3001     (void) q_link(cmd_ext_ptr, &cmd_ext_ptr->link);\r
3002     q_put(&nv_cmd_q, &cmd_ext_ptr->link);\r
3003   (void) rex_set_sigs(&nv_tcb, NV_CMD_Q_SIG);\r
3004 \r
3005   rex_wait( cmd_ptr->sigs );\r
3006   rex_clr_sigs( cmd_ptr->tcb_ptr, cmd_ptr->sigs );\r
3007 \r
3008   }\r
3009   else\r
3010     QSR_MSG_HIGH ( 3639666217ULL, "Could not allocate memory for variable of type nv_cmd_ext_type", 0, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
3011 \r
3012   /* Restore params */\r
3013 \r
3014   cmd_ptr->tcb_ptr = client_tcb;\r
3015   cmd_ptr->data_ptr = client_data;\r
3016 #else\r
3017   QSR_MSG_HIGH( 3143198573ULL, "nv_cmd_r():FEATURE_RPC not defined",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
3018 #endif\r
3019 } /* nv_cmd_r */\r
3020 \r
3021 /*===========================================================================\r
3022 \r
3023 FUNCTION NV_CMD_EXT_R\r
3024 \r
3025 DESCRIPTION\r
3026   This is same as nv_cmd but it waits till NV finishes its operation.\r
3027 \r
3028 DEPENDENCIES\r
3029   The NV task must have been started up already.  All of the items in\r
3030   the nv_cmd_block must be already set.\r
3031 \r
3032 RETURN VALUE\r
3033   None directly.  The status variable of the nv_cmd_type will be updated\r
3034   to reflect the current status of this command as it is processed.\r
3035 \r
3036 SIDE EFFECTS\r
3037   None.\r
3038 \r
3039 ===========================================================================*/\r
3040 \r
3041 void  \r
3042 nv_cmd_ext_r (\r
3043   nv_cmd_ext_type  *cmd_ext_ptr,                   /* Pointer to NV command buffer */\r
3044   nv_item_type *data_ptr /* Pointer to structure that contains item data */\r
3045 )\r
3046 {\r
3047 #ifdef FEATURE_RPC\r
3048   /* Save params */\r
3049   rex_tcb_type *client_tcb = cmd_ext_ptr->nvcmd->tcb_ptr;\r
3050   nv_item_type *client_data = cmd_ext_ptr->nvcmd->data_ptr;\r
3051 \r
3052   /* Set the request status to busy. initialize and link the command  */\r
3053   /* onto the NV command queue, set a signal to the NV task and exit. */\r
3054 \r
3055   cmd_ext_ptr->nvcmd->tcb_ptr = rex_self();\r
3056   cmd_ext_ptr->nvcmd->data_ptr = data_ptr;\r
3057 \r
3058   cmd_ext_ptr->nvcmd->status = NV_BUSY_S;\r
3059 \r
3060   /* Putting nv_cmd_ext on queue */\r
3061   (void) q_link(cmd_ext_ptr, &cmd_ext_ptr->link);\r
3062   q_put(&nv_cmd_q, &cmd_ext_ptr->link);\r
3063   (void) rex_set_sigs(&nv_tcb, NV_CMD_Q_SIG);\r
3064   \r
3065   rex_wait( cmd_ptr->sigs );\r
3066   rex_clr_sigs( cmd_ptr->tcb_ptr, cmd_ptr->sigs );\r
3067   \r
3068   /* Restore params */\r
3069   cmd_ext_ptr->nvcmd->tcb_ptr = client_tcb;\r
3070   cmd_ext_ptr->nvcmd->data_ptr = client_data;\r
3071 #else\r
3072   QSR_MSG_HIGH( 2675320387ULL, "nv_cmd_ext_r():FEATURE_RPC not defined",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
3073 #endif\r
3074   \r
3075 } /* nv_cmd_ext_r */\r
3076 \r
3077 \r
3078 /*===========================================================================\r
3079 \r
3080 FUNCTION NV_CMD_REMOTE\r
3081 \r
3082 DESCRIPTION\r
3083   This is the outside world's interface to the non volatile memory task.\r
3084 \r
3085 DEPENDENCIES\r
3086   The NV task must have been started up already.  All of the items in\r
3087   the nv_cmd_type must be already set.\r
3088 \r
3089 RETURN VALUE\r
3090 \r
3091   NV_DONE_S,      -  Request completed okay\r
3092   NV_BUSY_S,      -  Request is queued\r
3093   NV_BADCMD_S,    -  Unrecognizable command field\r
3094   NV_FULL_S,      -  The NVM is full\r
3095   NV_FAIL_S,      -  Command failed, reason other than NVM was full\r
3096   NV_NOTACTIVE_S, -  Variable was not active\r
3097   NV_BADPARM_S,   -  Bad parameter in command block\r
3098   NV_READONLY_S,  -  Parameter is write-protected and thus read only\r
3099   NV_BADTG_S,     -  Item not valid for Target\r
3100   NV_NOMEM_S,     -  free memory exhausted\r
3101   NV_NOTALLOC_S   -  address is not a valid allocation\r
3102 \r
3103 SIDE EFFECTS\r
3104   The nv_cmd_type is placed on the NV command queue.  It must not be\r
3105   modified until the command has been processed!\r
3106 \r
3107 ===========================================================================*/\r
3108 \r
3109 nv_stat_enum_type \r
3110 nv_cmd_remote (\r
3111   nv_func_enum_type cmd,\r
3112   nv_items_enum_type item,\r
3113   nv_item_type *data_ptr\r
3114 )\r
3115 {\r
3116   nv_cmd_type nv_rpc_cmd;\r
3117 #ifdef FEATURE_NV_RPC_SUPPORT\r
3118 \r
3119 #ifdef FEATURE_NV_ACCESS_FILTER\r
3120   if(cmd == NV_READ_F)\r
3121   {\r
3122     if(unreadable_nv_item(item))\r
3123     {\r
3124       return NV_BADPARM_S;   \r
3125     }\r
3126   }\r
3127   else \r
3128   { \r
3129     if((cmd == NV_WRITE_F)||(cmd == NV_REPLACE_F))\r
3130     {\r
3131       if(unwritable_nv_item(item))\r
3132       {\r
3133         return NV_BADPARM_S;   \r
3134       }\r
3135     }\r
3136   }\r
3137 #endif\r
3138 \r
3139   nv_rpc_cmd.status = NV_BUSY_S;\r
3140   (void) q_link(&nv_rpc_cmd, &nv_rpc_cmd.link);\r
3141   nv_rpc_cmd.tcb_ptr = rex_self();\r
3142   nv_rpc_cmd.sigs = NV_QIDS_RPC_SIG;\r
3143   nv_rpc_cmd.cmd = cmd;\r
3144   nv_rpc_cmd.item = item;\r
3145   nv_rpc_cmd.data_ptr = data_ptr;\r
3146   nv_rpc_cmd.done_q_ptr = NULL;\r
3147 \r
3148   nv_cmd( &nv_rpc_cmd );\r
3149   rex_wait( NV_QIDS_RPC_SIG ); /* this signal needs to be reserved for all worker task*/\r
3150 \r
3151   rex_clr_sigs( nv_rpc_cmd.tcb_ptr, NV_QIDS_RPC_SIG );\r
3152 \r
3153 #else\r
3154   QSR_MSG_HIGH( 2469021251ULL, "nv_stat_enum_type(): FEATURE_NV_RPC_SUPPORT not defined",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
3155   nv_rpc_cmd.status = NV_FAIL_S;\r
3156 #endif\r
3157   return nv_rpc_cmd.status;\r
3158 \r
3159 }\r
3160 \r
3161 /*===========================================================================\r
3162 \r
3163 FUNCTION NV_CMD_EXT_REMOTE\r
3164 \r
3165 DESCRIPTION\r
3166   This is the outside world's interface to the non volatile memory task.\r
3167 \r
3168 DEPENDENCIES\r
3169   The NV task must have been started up already.  All of the items in\r
3170   the nv_cmd_ext_type must be already set.\r
3171 \r
3172 RETURN VALUE\r
3173 \r
3174   NV_DONE_S,      -  Request completed okay\r
3175   NV_BUSY_S,      -  Request is queued\r
3176   NV_BADCMD_S,    -  Unrecognizable command field\r
3177   NV_FULL_S,      -  The NVM is full\r
3178   NV_FAIL_S,      -  Command failed, reason other than NVM was full\r
3179   NV_NOTACTIVE_S, -  Variable was not active\r
3180   NV_BADPARM_S,   -  Bad parameter in command block\r
3181   NV_READONLY_S,  -  Parameter is write-protected and thus read only\r
3182   NV_BADTG_S,     -  Item not valid for Target\r
3183   NV_NOMEM_S,     -  free memory exhausted\r
3184   NV_NOTALLOC_S   -  address is not a valid allocation\r
3185 \r
3186 SIDE EFFECTS\r
3187   The nv_cmd_ext_type is placed on the NV command queue.  It must not be\r
3188   modified until the command has been processed!\r
3189 \r
3190 ===========================================================================*/\r
3191 \r
3192 nv_stat_enum_type \r
3193 nv_cmd_ext_remote (\r
3194   nv_func_enum_type cmd,\r
3195   nv_items_enum_type item,\r
3196   nv_item_type *data_ptr,\r
3197   uint16 context\r
3198 )\r
3199 {\r
3200   nv_cmd_type nv_rpc_cmd;\r
3201 #ifdef FEATURE_NV_RPC_SUPPORT\r
3202   nv_cmd_ext_type nv_rpc_cmd_ext;\r
3203 \r
3204 #ifdef FEATURE_NV_ACCESS_FILTER\r
3205   if(cmd == NV_READ_F)\r
3206   {\r
3207     if(unreadable_nv_item(item))\r
3208     {\r
3209       return NV_BADPARM_S;   \r
3210     }\r
3211   }\r
3212   else \r
3213   { \r
3214     if((cmd == NV_WRITE_F)||(cmd == NV_REPLACE_F))\r
3215     {\r
3216       if(unwritable_nv_item(item))\r
3217       {\r
3218         return NV_BADPARM_S;   \r
3219       }\r
3220     }\r
3221   }\r
3222 #endif\r
3223 \r
3224   nv_rpc_cmd.status = NV_BUSY_S;\r
3225   (void) q_link(&nv_rpc_cmd, &nv_rpc_cmd.link);\r
3226   nv_rpc_cmd.tcb_ptr = rex_self();\r
3227   nv_rpc_cmd.sigs = NV_QIDS_RPC_SIG;\r
3228   nv_rpc_cmd.cmd = cmd;\r
3229   nv_rpc_cmd.item = item;\r
3230   nv_rpc_cmd.data_ptr = data_ptr;\r
3231   nv_rpc_cmd.done_q_ptr = NULL;\r
3232   \r
3233   nv_rpc_cmd_ext.nvcmd = &nv_rpc_cmd;\r
3234   nv_rpc_cmd_ext.context = context;\r
3235   (void) q_link(&nv_rpc_cmd_ext, &nv_rpc_cmd_ext.link);\r
3236   \r
3237   nv_cmd_ext( &nv_rpc_cmd_ext );\r
3238   rex_wait( NV_QIDS_RPC_SIG ); /* this signal needs to be reserved for all worker task*/\r
3239 \r
3240   rex_clr_sigs( nv_rpc_cmd.tcb_ptr, NV_QIDS_RPC_SIG );\r
3241 \r
3242 #else\r
3243   QSR_MSG_HIGH( 2201780199ULL, "nv_cmd_ext_remote(): FEATURE_NV_RPC_SUPPORT not defined",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
3244   nv_rpc_cmd.status = NV_FAIL_S;\r
3245 #endif\r
3246 \r
3247   return nv_rpc_cmd.status;\r
3248 \r
3249 }\r
3250 \r
3251 /*===========================================================================\r
3252 \r
3253 FUNCTION NV_RTRE_USE_RUIM_FOR_NAM\r
3254 \r
3255 DESCRIPTION\r
3256   This function determines if the R-UIM is to be used (based on RTRE control)\r
3257   and the NAM is the R-UIM NAM.\r
3258   \r
3259 DEPENDENCIES\r
3260   The return value has a default setting and is updated when NV receives\r
3261   a NV_RTRE_OP_CONFIG_F command.\r
3262 \r
3263 RETURN VALUE\r
3264   The RTRE control indicates to use the R-UIM and the NAM matches the R-UIM \r
3265   NAM.\r
3266 \r
3267 SIDE EFFECTS\r
3268   This function uses the current value of the RTRE control.  It may\r
3269   change.\r
3270 \r
3271 ===========================================================================*/\r
3272 \r
3273 boolean \r
3274 nv_rtre_use_ruim_for_nam (\r
3275   byte nam\r
3276 )\r
3277 {\r
3278   #ifdef FEATURE_UIM_RUN_TIME_ENABLE\r
3279     /* Determine if the current RTRE control is for the R-UIM */\r
3280     return ((NV_RTRE_CONTROL_USE_RUIM == nv_rtre_control()) &&\r
3281     /* and the NAM matches the R-UIM NAM */\r
3282             (NV_RUIM_NAM == nam));\r
3283   #else\r
3284     (void)nam;\r
3285     return FALSE;\r
3286   #endif /*FEATURE_UIM_RUN_TIME_ENABLE*/\r
3287 }\r
3288 \r
3289 /*==================================================================\r
3290 Function: NV_ACCESS_OP_CS_INIT\r
3291 \r
3292 Description: This functions initialises kxmutex.\r
3293 ==================================================================*/\r
3294 \r
3295 void nv_access_op_cs_init(void)\r
3296 {\r
3297   if (!(KxMutex_Init(&nv_access_op_cs,"KXMUTEX_NV_ACCESS_OP_CS"))) \r
3298   {\r
3299     ERR_FATAL("nv_access_op_cs KxMutex_Alloc Failed",0,0,0);\r
3300   }\r
3301   nv_cs_init_flag = TRUE;\r
3302 }\r
3303 \r
3304 /*===========================================================================\r
3305 \r
3306 FUNCTION NV_RTRE_CONTROL\r
3307 \r
3308 DESCRIPTION\r
3309   This function provides the current RTRE control.  The control indicates \r
3310   whether the use the R-UIM in an operation or not.\r
3311 \r
3312 DEPENDENCIES\r
3313   The return value has a default setting and is updated when NV receives\r
3314   a NV_RTRE_OP_CONFIG_F command.\r
3315 \r
3316 RETURN VALUE\r
3317   The RTRE control\r
3318 \r
3319 SIDE EFFECTS\r
3320   This function returns the current value of the RTRE control.  It may\r
3321   change.\r
3322 \r
3323 ===========================================================================*/\r
3324 \r
3325 nv_rtre_control_type \r
3326 nv_rtre_control( void ) \r
3327 {\r
3328 #ifdef FEATURE_UIM_RUN_TIME_ENABLE\r
3329     /* Retrieve the current RTRE control value */\r
3330   return (nv_rtre_control_value);\r
3331 #else\r
3332   return NV_RTRE_CONTROL_NO_RUIM;\r
3333   #endif /*FEATURE_UIM_RUN_TIME_ENABLE*/\r
3334 \r
3335 }\r
3336 \r
3337 /*===========================================================================\r
3338 \r
3339 FUNCTION NV_RTRE_POLLING_CONTROL\r
3340 \r
3341 DESCRIPTION\r
3342   This function provides the current RTRE polling control.  The polling control\r
3343   indicates whether to poll the UIM card when originating a call or while on \r
3344   the traffic channel.\r
3345 \r
3346 DEPENDENCIES\r
3347   The return value has a default setting and is updated when NV receives\r
3348   a NV_RTRE_OP_CONFIG_F command.\r
3349 \r
3350 RETURN VALUE\r
3351   The RTRE polling control\r
3352 \r
3353 SIDE EFFECTS\r
3354   This function returns the current value of the RTRE polling control.  It may\r
3355   change.\r
3356 \r
3357 ===========================================================================*/\r
3358 \r
3359 nv_rtre_polling_control_type \r
3360 nv_rtre_polling_control( void ) {\r
3361 #ifdef FEATURE_UIM_RUN_TIME_ENABLE\r
3362     /* Retrieve the current RTRE control value */\r
3363   return (nv_rtre_polling_control_value);\r
3364 #else\r
3365   return NV_RTRE_POLLING_CONTROL_NO_POLL;\r
3366   #endif /*FEATURE_UIM_RUN_TIME_ENABLE*/\r
3367 }\r
3368 \r
3369 /*===========================================================================\r
3370 \r
3371 FUNCTION NV_RTRE_POLLING_FOR_NAM\r
3372 \r
3373 DESCRIPTION\r
3374   This function provides the current RTRE polling control when the NAM is the \r
3375   R_UIM NAM.  The polling control indicates whether to poll the UIM card when \r
3376   originating a call or while on the traffic channel.\r
3377 \r
3378 DEPENDENCIES\r
3379   The return value has a default setting and is updated when NV receives\r
3380   a NV_RTRE_OP_CONFIG_F command.\r
3381 \r
3382 RETURN VALUE\r
3383   The RTRE polling control indicates whether to poll and the NAM matches the\r
3384   R-UIM NAM.\r
3385 \r
3386 SIDE EFFECTS\r
3387   This function returns the current value of the RTRE polling control.  It may\r
3388   change.\r
3389 \r
3390 ===========================================================================*/\r
3391 \r
3392 boolean \r
3393 nv_rtre_polling_for_nam ( \r
3394   byte nam\r
3395 )\r
3396 {\r
3397 #ifdef FEATURE_UIM_RUN_TIME_ENABLE\r
3398    /* Retrieve the current RTRE control value */\r
3399    return ((NV_RTRE_POLLING_CONTROL_POLL == nv_rtre_polling_control_value) &&\r
3400    /* and the NAM matches the R-UIM NAM */\r
3401             (NV_RUIM_NAM == nam));\r
3402 #else\r
3403    (void)nam;\r
3404    return FALSE;\r
3405   #endif /*FEATURE_UIM_RUN_TIME_ENABLE*/\r
3406 }\r
3407 \r
3408 \r
3409 #endif /* FEATURE_NV_ITEM_MGR */\r