mirror from https://www.codeaurora.org/git/projects/hisense-ts7008/repository/
[huawei.git] / AMSS / nv / nvio.c
1 /*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*\r
2 \r
3          N V   I T E M    M A N A G E R    IO   S E R V I C E S\r
4 \r
5 GENERAL DESCRIPTION\r
6   This module provides the NV I/O services using EFS items.\r
7   \r
8 EXTERNALIZED FUNCTIONS\r
9   nvio_write\r
10     This is the function which writes NV items into the EFS.\r
11   nvio_read\r
12     This is the function which reads NV items from the EFS.\r
13 \r
14 INITIALIZATION AND SEQUENCING REQUIREMENTS\r
15 \r
16 Copyright (c) 2005-2010 by QUALCOMM, Incorporated.\r
17 All Rights Reserved.\r
18 Qualcomm Confidential and Proprietary\r
19 *====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*/\r
20 /*===========================================================================\r
21 \r
22 \r
23                         EDIT HISTORY FOR MODULE\r
24 \r
25 This section contains comments describing changes made to the module.\r
26 Notice that changes are listed in reverse chronological order.\r
27 \r
28 $Header: //source/qcom/qct/core/pkg/2H09/halcyon_modem/rel/LA2.0/AMSS/products/7x30/core/services/nv/src/nvio.c#1 $\r
29 \r
30 when       who     what, where, why\r
31 --------   ---     ----------------------------------------------------------\r
32 09/25/09   pc      Dual SIM/Dual Standby support for LCU\r
33 05/27/09   sri     included header file nvio.h, modified function prototype\r
34                    nvio_read_prl_item()\r
35 04/01/09   sri     nvio_write_roaming_list modified to avoid write_buf \r
36                    over writing\r
37 05/04/05   pc      Creation of NV2\r
38    \r
39 \r
40 ===========================================================================*/\r
41 \f\r
42 /*===========================================================================\r
43 \r
44                      INCLUDE FILES FOR MODULE\r
45 \r
46 ===========================================================================*/\r
47 \r
48 #include "target.h"\r
49 #include "comdef.h"\r
50 \r
51 #ifdef FEATURE_NV_ITEM_MGR\r
52 \r
53 #include "nvi.h"\r
54 #include "msg.h"\r
55 #include "crc.h"\r
56 #include "err.h"\r
57 #include "memory.h"\r
58 #include "dog.h"\r
59 #include "nvim.h"\r
60 #include "fs_public.h"\r
61 #include "nv_items.h"\r
62 #include "nvio.h"\r
63 \r
64 #ifdef FEATURE_NV_RUIM\r
65 #include "nvruimi.h"\r
66 #endif\r
67 \r
68 #ifdef FEATURE_NV_SUPPORT_FLASH_OTP\r
69 #include "flash_otp.h"\r
70 #endif\r
71 \r
72 #ifdef FEATURE_NV_SFS_PRIVATE\r
73 #include "sfs_private.h"\r
74 #endif\r
75 \f\r
76 /*===========================================================================\r
77 \r
78                 DEFINITIONS AND DECLARATIONS FOR MODULE\r
79 \r
80 This section contains definitions for constants, macros, types, variables\r
81 and other items needed by this module.\r
82 \r
83 ===========================================================================*/\r
84 \r
85 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
86 /*                                                                         */\r
87 /*                         DATA DEFINITIONS                                */\r
88 /*                                                                         */\r
89 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
90 \r
91 extern nvi_item_type            nvi_item;\r
92 extern boolean                 nvi_initialized;\r
93 \r
94 #ifdef NV_FEATURE_RENTAL_ITEMS\r
95 #error code not present\r
96 #endif\r
97 \r
98 #ifdef NV_FEATURE_FACTORY_INFO\r
99   /* Factory data block cache for peek/poke access */\r
100   extern byte fact_data[NVIM_FACTORY_DATA_SIZE];\r
101 #endif\r
102 \r
103 /* Dynamic pool available in EFS */\r
104 extern word                   nvi_memavail_data;\r
105 \r
106 extern boolean  nv_prl_valid_data[NV_MAX_NAMS];\r
107 extern word     nv_prl_version_data[NV_MAX_NAMS];\r
108 \r
109 rex_crit_sect_type nv_crit_sect;\r
110 \r
111 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
112 /*                                                                         */\r
113 /*                      REX Timers and Queues                              */\r
114 /*                                                                         */\r
115 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
116 \r
117 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
118 /*                                                                         */\r
119 /*                            Local Data                                   */\r
120 /*                                                                         */\r
121 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
122 \r
123 #ifdef NV_FEATURE_DIAG_WINS\r
124    static boolean                  write_gate_open = TRUE;\r
125 #endif\r
126 \r
127 \r
128 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
129 \r
130 \r
131 /*===========================================================================\r
132 \r
133 FUNCTION NVR_TRANSLATE_TO_EXTERNAL\r
134 \r
135 DESCRIPTION\r
136   This function translates a digit from internal 4 bit NVM storage\r
137   to external 8 bit ASCII representation.\r
138 \r
139 DEPENDENCIES\r
140   None.\r
141 \r
142 RETURN VALUE\r
143   The 8 bit ASCII digit value.\r
144 \r
145 SIDE EFFECTS\r
146   None.\r
147 \r
148 ===========================================================================*/\r
149 \r
150 LOCAL byte \r
151 nvr_translate_to_external ( \r
152   byte   digit    /* Internal digit representation */\r
153 )\r
154 {\r
155   if (digit <= 0x09) return(digit + '0');\r
156   else if (digit == 0x0A) return('*');\r
157   else if (digit == 0x0B) return('#');\r
158   else if (digit == 0x0C) return('-');\r
159   else if (digit == 0x0D) return('P');\r
160   else if (digit == 0x0E) return('T');\r
161   else return('L');\r
162 \r
163 } /* nvr_translate_to_external */\r
164 \r
165 /*===========================================================================\r
166 \r
167 FUNCTION NVIO_READ_ITEM\r
168 \r
169 DESCRIPTION\r
170   This function reads an NV item from NV database.\r
171 \r
172 DEPENDENCIES\r
173   None.\r
174 \r
175 RETURN VALUE\r
176   NV_DONE_S if it worked\r
177   NV_FAIL_S if it did not work.\r
178 \r
179 SIDE EFFECTS\r
180 \r
181 ===========================================================================*/\r
182 nv_stat_enum_type \r
183 nvio_read_item (\r
184   nv_items_enum_type    item,\r
185   byte   index,\r
186   void   * data_ptr,\r
187   uint32 item_size,\r
188   uint16     context\r
189 )\r
190 {\r
191   int   return_size;\r
192   char  f_name[120];\r
193   nv_stat_enum_type status;\r
194   struct fs_stat temp_buf;\r
195 \r
196   /* Create the name of the item file */\r
197   /* Check if context is defined while constructing pathname */\r
198   if (context == 0) { /* No context is defined, use old pathname */\r
199   if(index == 0)\r
200     (void)snprintf(f_name,sizeof(f_name),"/nvm/num/%d",item);\r
201   else\r
202     (void)snprintf(f_name,sizeof(f_name),"/nvm/num/%d_%d",item,index); \r
203   }\r
204   else { /* use context while constructing pathname*/\r
205     if(index == 0)\r
206       (void)snprintf(f_name,sizeof(f_name),"/nvm/context%d/%d",context,item);\r
207     else\r
208       (void)snprintf(f_name,sizeof(f_name),"/nvm/context%d/%d_%d",context,item,index);\r
209   }\r
210 \r
211   /* Check if the file is present or not. */\r
212   if(efs_stat(f_name,&temp_buf) == -1) {\r
213     return NV_NOTACTIVE_S;\r
214   }\r
215 \r
216   if((temp_buf.st_size) != (nvim_op_get_size(item)))\r
217   {\r
218     (void)efs_unlink(f_name);\r
219     return NV_NOTACTIVE_S;\r
220   }\r
221     \r
222   /* Obtain the contents from EFS */\r
223   return_size = efs_get(f_name, data_ptr, item_size);\r
224 \r
225   if (return_size == -1)\r
226     status = NV_FAIL_S;\r
227   else\r
228     status = NV_DONE_S;\r
229 \r
230   return status;\r
231 } /* End of nvio_read_item*/\r
232 \r
233 \f\r
234 /*===========================================================================\r
235 \r
236 FUNCTION NVIO_READ_DIAL\r
237 \r
238 DESCRIPTION\r
239   This procedure processes read requests for speed dial numbers.  It reads\r
240   the NV item and it performs necessary translations and copy from internal \r
241   format to external format.\r
242 \r
243 DEPENDENCIES\r
244   None.\r
245 \r
246 RETURN VALUE\r
247   Status of the read request.\r
248 \r
249 SIDE EFFECTS\r
250   None.\r
251 \r
252 ===========================================================================*/\r
253 \r
254 LOCAL nv_stat_enum_type \r
255 nvio_read_dial (\r
256   nv_items_enum_type    item,         /* Item to access */\r
257   byte                  index_range,  /* Maximum allowed range for index */\r
258   byte                  index,        /* speed dial # */\r
259   nv_dial_type          *dial_ptr,     /* Pointer to write source buffer */\r
260   byte                  item_context   /* Context for NV path */\r
261 )\r
262 {\r
263   word   i;                           /* Digit index */\r
264   word ndigits;                       /* # of digits being processed */\r
265   nv_stat_enum_type status; /* Status to return to calling procedure */\r
266 \r
267 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
268 \r
269   /* Read the number from NVM into internal buffer. */\r
270 \r
271   if (index >= index_range) {\r
272     return NV_BADPARM_S;\r
273   }\r
274 \r
275   status = nvio_read_item(\r
276                            item,\r
277                            index,\r
278 #ifdef NV_FEATURE_EXTENDED_UI\r
279                            (byte*)&nvi_item.dial.status,    \r
280 #else\r
281                            (byte*)&nvi_item.dial.num_digits,\r
282 #endif\r
283                            sizeof(nvi_item.dial),\r
284                            item_context);\r
285   if(status == NV_DONE_S)\r
286   {\r
287     /* Copy the number of dial digits stored, making  */\r
288     /* sure that if there was an NV error only the    */\r
289     /* maximum number of dialed digits will be read.  */\r
290 \r
291     dial_ptr->num_digits = MIN(nvi_item.dial.num_digits, NV_MAX_DIAL_DIGITS);\r
292 \r
293     /* Copy the digits, expanding from two digits per  */\r
294     /* byte into one digits per byte, and translating  */\r
295     /* the digit to external character representation. */\r
296 \r
297     ndigits = dial_ptr->num_digits;\r
298     for (i = 0; i < ndigits; i++) {\r
299 \r
300       /* Even digits are copied from least significant digit,  */\r
301       /* odd digits are copied from most significant digit.    */\r
302 \r
303       if(i%2 == 0){\r
304         dial_ptr->digits[i] = \r
305           nvr_translate_to_external(\r
306              (byte)(nvi_item.dial.digits[i/2] & 0x0F));\r
307       }\r
308       else{\r
309         dial_ptr->digits[i] = \r
310           nvr_translate_to_external(\r
311              (byte)((nvi_item.dial.digits[i/2] & 0xF0) >> 4));\r
312       }\r
313     } /* for */\r
314 \r
315     /* Move name into external type. */\r
316     (void)memcpy((void *) dial_ptr->letters, (void *) nvi_item.dial.letters,\r
317                   NV_MAX_LTRS);\r
318   }\r
319 \r
320 #ifdef NV_FEATURE_EXTENDED_UI\r
321       dial_ptr->status = nvi_item.dial.status;\r
322 #endif\r
323   return status;\r
324 \r
325 } /* nvio_read_dial */\r
326 \f\r
327 \f\r
328 /*===========================================================================\r
329 \r
330 FUNCTION NVIO_READ_STDIAL\r
331 \r
332 DESCRIPTION\r
333   This procedure processes read requests for speed dial numbers.  It reads\r
334   the NV item and it performs necessary translations and copy from internal \r
335   format to external format.\r
336 \r
337 DEPENDENCIES\r
338   None.\r
339 \r
340 RETURN VALUE\r
341   Status of the read request.\r
342 \r
343 SIDE EFFECTS\r
344   None.\r
345 \r
346 ===========================================================================*/\r
347 \r
348 LOCAL nv_stat_enum_type \r
349 nvio_read_stdial (\r
350   nv_items_enum_type    item,        /* Item to access */\r
351   byte                  index_range, /* Maximum allowed range for index */\r
352   byte                  index,       /* speed dial # */\r
353   nv_stdial_type        *dial_ptr,    /* Pointer to write source buffer */\r
354   byte                  item_context  /* Context for NV path */\r
355 )\r
356 {\r
357   word   i;                 /* Digit index */\r
358   nv_stat_enum_type status; /* Status to return to calling procedure */\r
359 \r
360 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
361 \r
362   /* Read the number from NV into internal buffer. */\r
363 \r
364   if (index >= index_range) return NV_BADPARM_S;\r
365 \r
366   status = nvio_read_item(\r
367                           item,\r
368                           index,\r
369 #ifdef NV_FEATURE_EXTENDED_UI\r
370                           (byte*)&nvi_item.stack.status,     \r
371 #else\r
372                           (byte*)&nvi_item.stack.num_digits, \r
373 #endif\r
374                           sizeof(nvi_item.stack),\r
375                           item_context);\r
376 \r
377   if(status == NV_DONE_S)\r
378   {\r
379     /* Copy the number of dial digits stored, making  */\r
380     /* sure that if there was an NVM error only the   */\r
381     /* maximum number of dialed digits will be read.  */\r
382 \r
383     dial_ptr->num_digits = MIN(nvi_item.stack.num_digits, NV_MAX_DIAL_DIGITS);\r
384 \r
385     /* Copy the digits, expanding from two digits per  */\r
386     /* byte into one digits per byte, and translating  */\r
387     /* the digit to external character representation. */\r
388 \r
389     for (i = 0; i < dial_ptr->num_digits; i++) {\r
390 \r
391       /* Even digits are copied from least significant digit,  */\r
392       /* odd digits are copied from most significant digit.    */\r
393 \r
394       if(i%2 == 0)\r
395         dial_ptr->digits[i] = nvr_translate_to_external((byte)(nvi_item.stack.digits[i/2] & 0x0F));\r
396       else\r
397         dial_ptr->digits[i] = nvr_translate_to_external((byte)((nvi_item.stack.digits[i/2] & 0xF0) >> 4));\r
398     } /* for */\r
399 \r
400     /* Move name into external type. */\r
401     (void)memcpy((void *) dial_ptr->letters, (void *) nvi_item.stack.letters,\r
402                   NV_MAX_LTRS);\r
403   }\r
404 \r
405 #ifdef NV_FEATURE_EXTENDED_UI\r
406       dial_ptr->status = nvi_item.stack.status;\r
407       dial_ptr->time_stamp = nvi_item.stack.time_stamp;\r
408       dial_ptr->duration = nvi_item.stack.duration;\r
409 #endif\r
410   return status;\r
411 \r
412 } /* nvio_read_stdial */\r
413 \r
414 \f\r
415 /*===========================================================================\r
416 \r
417 FUNCTION NVIO_READ_SMS\r
418 \r
419 DESCRIPTION\r
420   This function reads an sms depending upon the address (index) of sms \r
421   passed into it via the cmd_ptr.\r
422 \r
423 DEPENDENCIES\r
424   None.\r
425 \r
426 RETURN VALUE\r
427   NV_DONE_S    if it worked\r
428   NV_BADPARM_S if requested bytes are out of range for NVM\r
429 \r
430 SIDE EFFECTS\r
431   None\r
432 \r
433 ===========================================================================*/\r
434 \r
435 LOCAL nv_stat_enum_type \r
436 nvio_read_sms (\r
437   nv_cmd_ext_type  *cmd_ext_ptr          /* Command block */\r
438 )\r
439 {\r
440   int return_size;\r
441   /* Increase size of sms name from 20 to 28 to accomodate\r
442      the 8 characters for context */\r
443   char sms_name[28];\r
444   nv_stat_enum_type   status = NV_DONE_S;\r
445   struct fs_stat temp_buf;\r
446 \r
447   /* only sms supported at this time */\r
448   if(((cmd_ext_ptr->nvcmd->item != NV_SMS_I) && (cmd_ext_ptr->nvcmd->item != NV_SMS_DM_I))\r
449      || (cmd_ext_ptr->nvcmd->data_ptr->sms.address >= NVI_MAX_SMS_ADDR)) {\r
450     status = NV_BADPARM_S;\r
451   }\r
452 \r
453   else{\r
454     /* Reset the watchdog timer */\r
455     KICK_WATCHDOG();\r
456 \r
457     /* Create the name of the file to be read */\r
458     /* Check if context is defined*/\r
459     if (cmd_ext_ptr->context == 0) /* Context is not defined*/\r
460     (void) snprintf(sms_name, sizeof(sms_name), "/nvm/sms_%05d",\r
461                                           cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
462     else /* Context is defined */\r
463       (void) snprintf(sms_name, sizeof(sms_name), "/nvm/context%d/sms_%05d",\r
464                       cmd_ext_ptr->context,\r
465                       cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
466 \r
467     /* Check if the file present or not. */\r
468     if(efs_stat(sms_name,&temp_buf) == -1) {\r
469       status = NV_NOTACTIVE_S;\r
470     }\r
471     else {\r
472 \r
473       if(((cmd_ext_ptr->nvcmd->item == NV_SMS_I)&&\r
474             (temp_buf.st_size > (NV_SMS_DATA_SIZ + sizeof(nvi_sms_type))))\r
475          ||((cmd_ext_ptr->nvcmd->item == NV_SMS_DM_I)&&\r
476             (temp_buf.st_size > (NV_SMS_DATA_SIZ + sizeof(nvi_sms_type))))){\r
477         QSR_MSG_HIGH ( 305830160ULL, "SMS Buffer not big enough for slot %d",\r
478                         cmd_ext_ptr->nvcmd->data_ptr->sms.address, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
479         status = NV_FAIL_S;\r
480       }\r
481       else {\r
482 \r
483         /* Read the contents from EFS */\r
484         return_size = efs_get( sms_name,\r
485                                (byte *)&(cmd_ext_ptr->nvcmd->data_ptr->sms.address),\r
486                                (int)temp_buf.st_size);\r
487         if(return_size == -1) {\r
488           status = NV_FAIL_S;\r
489         }\r
490       }\r
491     }\r
492   }\r
493   return status;\r
494 } /* nvio_read_sms */\r
495 \r
496 \f\r
497 #ifdef FEATURE_GWSMS\r
498 /*===========================================================================\r
499 \r
500 FUNCTION NVIO_READ_SMS_GW\r
501 \r
502 DESCRIPTION\r
503   This function reads from an sms_gw location\r
504 \r
505 DEPENDENCIES\r
506   None.\r
507 \r
508 RETURN VALUE\r
509   NV_DONE_S    if it worked\r
510   NV_BADPARM_S if requested bytes are out of range for NVM\r
511 \r
512 SIDE EFFECTS\r
513   None\r
514 \r
515 ===========================================================================*/\r
516 \r
517 LOCAL nv_stat_enum_type \r
518 nvio_read_sms_gw (\r
519   nv_cmd_ext_type  *cmd_ext_ptr          /* Command block */\r
520 )\r
521 {\r
522   int                 return_size;\r
523   char                sms_name[28];/* Incrementing size from 20 to 28 for context*/\r
524   nv_stat_enum_type   status = NV_DONE_S;\r
525   struct fs_stat      temp_buf;\r
526 \r
527   if ((cmd_ext_ptr->nvcmd->item != NV_SMS_GW_I)||\r
528       (cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address >= NVI_MAX_SMS_ADDR)) {\r
529     status = NV_BADPARM_S;\r
530   }\r
531   else {\r
532 \r
533     /* Reset the watchdog timer */\r
534     KICK_WATCHDOG();\r
535 \r
536     /* Create the name of the file being read.*/\r
537     if (cmd_ext_ptr->context == 0) /* No context defined */\r
538     (void)snprintf(sms_name, sizeof(sms_name), "/nvm/sms_gw_%05d",\r
539                      cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
540     else /* Context defined */\r
541       (void)snprintf(sms_name, sizeof(sms_name), "/nvm/context%d/sms_gw_%05d",\r
542                      cmd_ext_ptr->context,\r
543                      cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
544     /* Check if the file is present or not. */\r
545     if(efs_stat(sms_name,&temp_buf) == -1){\r
546       status = NV_NOTACTIVE_S;\r
547     }\r
548     else {\r
549       if (temp_buf.st_size > (NV_SMS_GW_DATA_SIZ + sizeof(nvi_sms_gw_type))) {\r
550         /* Buffer not big enough to hold the message */\r
551         QSR_MSG_HIGH ( 305830160ULL, "SMS Buffer not big enough for slot %d",\r
552                    cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
553         status = NV_FAIL_S;\r
554       }\r
555       else {\r
556         /* Extract the data from EFS */\r
557         return_size = efs_get( sms_name,\r
558                                (byte *)&(cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address),\r
559                                (int)temp_buf.st_size);\r
560         if(return_size == -1) {\r
561           status = NV_FAIL_S;\r
562         }\r
563       }\r
564     }\r
565   }\r
566   return status;\r
567 } /* nvio_read_sms_gw */\r
568 #endif\r
569 \r
570 \f\r
571 /*===========================================================================\r
572 \r
573 FUNCTION NVIO_READ_PRL_ITEM\r
574 \r
575 DESCRIPTION\r
576   This function reads a PRL item from NVM directory\r
577 \r
578 DEPENDENCIES\r
579   None.\r
580 \r
581 RETURN VALUE\r
582   NV_DONE_S if it worked\r
583   NV_FAIL_S if it did not work.\r
584 \r
585 SIDE EFFECTS\r
586 \r
587 ===========================================================================*/\r
588 nv_stat_enum_type \r
589 nvio_read_prl_item (\r
590   int num,\r
591   void * data_ptr,\r
592   int item_size\r
593 )\r
594 {\r
595   nv_stat_enum_type  status;      /* Function return value */  \r
596   int                fd;\r
597   char               f_name[120];\r
598   struct fs_stat     temp_buf;\r
599   char               *read_buf;\r
600   fs_ssize_t         result = 0;\r
601   fs_size_t          nbytes;\r
602   fs_size_t          bytes_read;\r
603 \r
604   QSR_MSG_MED( 2779538831ULL, "size: %d", item_size, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
605 \r
606   snprintf(f_name,sizeof(f_name),"/nvm/prl_%d",num);\r
607 \r
608     /* Check if the file is present or not. */\r
609   if(efs_stat(f_name,&temp_buf) == -1) {\r
610     return NV_NOTACTIVE_S;\r
611   }\r
612 \r
613   fd = efs_open(f_name, O_RDWR, 0777 );\r
614 \r
615   nbytes = item_size;\r
616   read_buf = data_ptr;\r
617 \r
618   efs_read (fd,\r
619             (void *) (read_buf),\r
620             sizeof(boolean));\r
621 \r
622   efs_lseek(fd,sizeof(boolean),SEEK_CUR);\r
623 \r
624   bytes_read = 1;\r
625 \r
626   while (bytes_read < nbytes)\r
627   {\r
628     result = efs_read (fd,\r
629                        (void *) (read_buf + bytes_read),\r
630                        nbytes - bytes_read);\r
631     if (result <= 0)\r
632     break;\r
633     bytes_read += (fs_size_t) result;\r
634   }\r
635 \r
636   efs_close(fd);\r
637 \r
638   if (result == -1) {\r
639     status = NV_FAIL_S;\r
640   }\r
641   else status = NV_DONE_S;\r
642 \r
643   if (status == NV_DONE_S) {\r
644     nv_prl_version_data[num] = ((nv_roaming_list_header_type *)read_buf)->prl_version;\r
645     nv_prl_valid_data[num] = ((nv_roaming_list_header_type *)read_buf)->valid;\r
646   }\r
647   else {\r
648     nv_prl_version_data[num] = NV_PRL_VERSION_INVALID;\r
649     nv_prl_valid_data[num] = FALSE;\r
650   }\r
651 \r
652   return status;\r
653 }\r
654 \r
655 \f\r
656 /*===========================================================================\r
657 \r
658 FUNCTION NVIO_READ_RENTAL_TIMER\r
659 \r
660 DESCRIPTION\r
661   This function returns the current value of the rental timer item.  Since\r
662   this item is expected to be updated with very high frequency, it is stored \r
663   in a way that minimizes EEPROM cell wear.  This unusual storage format \r
664   calls for a special routine to compute and return the value for reads.\r
665   \r
666 DEPENDENCIES\r
667   None.\r
668 \r
669 RETURN VALUE\r
670   NV_DONE_S       if it worked\r
671   NV_NOTACTIVE_S  if the item is uninitialized\r
672 \r
673 SIDE EFFECTS\r
674   None\r
675 \r
676 ===========================================================================*/\r
677 #ifdef NV_FEATURE_RENTAL_ITEMS\r
678 #error code not present\r
679 #endif\r
680 \r
681 \f\r
682 /*===========================================================================\r
683 \r
684 FUNCTION NVIO_READ_RENTAL_CNT\r
685 \r
686 DESCRIPTION\r
687   This function returns the current value of the rental count item.  Since\r
688   this item is a fixed-pool double-buffered item, it needs a special read\r
689   routine.\r
690   \r
691 DEPENDENCIES\r
692   None.\r
693 \r
694 RETURN VALUE\r
695   NV_DONE_S       if it worked\r
696   NV_NOTACTIVE_S  if the item is uninitialized\r
697 \r
698 SIDE EFFECTS\r
699   None\r
700 \r
701 ===========================================================================*/\r
702 #ifdef NV_FEATURE_RENTAL_ITEMS\r
703 #error code not present\r
704 #endif\r
705 \r
706 \f\r
707 #ifdef NV_FEATURE_PRL_ITEMS\r
708 /*===========================================================================\r
709 \r
710 FUNCTION NVIO_READ_ROAMING_LIST\r
711 \r
712 DESCRIPTION\r
713   This function reads the roaming list. \r
714 \r
715 DEPENDENCIES\r
716   None.\r
717 \r
718 RETURN VALUE\r
719   NV_DONE_S    if it worked\r
720   NV_BADPARM_S if requested bytes are out of range for NVM\r
721 \r
722 SIDE EFFECTS\r
723   None\r
724 \r
725 ===========================================================================*/\r
726 \r
727 LOCAL nv_stat_enum_type \r
728 nvio_read_roaming_list (\r
729   nv_cmd_ext_type  *cmd_ext_ptr\r
730 )\r
731 {\r
732   word               item_size;   /* Size of item (in bytes) */\r
733   nv_stat_enum_type  status;      /* Function return value */  \r
734   int                fd;\r
735   char               f_name[128]; /* Increase size from 120 to 128 for context*/\r
736   struct fs_stat     temp_buf;\r
737   char               *read_buf;\r
738   fs_ssize_t         result = 0;\r
739   fs_size_t          nbytes;\r
740   fs_size_t          bytes_read;\r
741   boolean            nam_flag;\r
742 \r
743   /* Check for illegal NAM */\r
744   if(cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam >= NV_MAX_NAMS) {\r
745     return NV_BADPARM_S;\r
746   }\r
747         \r
748   /* Get its size */\r
749   item_size = NV_ROAMING_LIST_HEADER_SIZE +\r
750                  nv_max_size_of_roaming_list();\r
751 \r
752 \r
753   QSR_MSG_MED( 2779538831ULL, "size: %d", item_size, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
754  \r
755   if (cmd_ext_ptr->context == 0) /* No context is defined*/\r
756     snprintf(f_name,sizeof(f_name),"/nvm/prl_%d",\r
757              cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam);\r
758   else /* Context is defined */\r
759     snprintf(f_name,sizeof(f_name),"/nvm/context%d/prl_%d",\r
760              cmd_ext_ptr->context,cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam);\r
761   \r
762     /* Check if the file is present or not. */\r
763   if(efs_stat(f_name,&temp_buf) == -1) {\r
764     return NV_NOTACTIVE_S;\r
765   }\r
766 \r
767   fd = efs_open(f_name, O_RDWR, 0777 );\r
768 \r
769   nbytes = item_size;\r
770   bytes_read = 0;\r
771   read_buf = (void *) &(cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version);\r
772 \r
773   efs_lseek(fd,\r
774             sizeof(nam_flag) + sizeof(cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam),\r
775             SEEK_CUR);\r
776 \r
777   while (bytes_read < nbytes)\r
778   {\r
779     result = efs_read (fd,\r
780                        (void *) (read_buf + bytes_read),\r
781                        nbytes - bytes_read);\r
782     if (result <= 0)\r
783       break;\r
784     bytes_read += (fs_size_t) result;\r
785   }\r
786 \r
787   efs_close(fd);\r
788 \r
789   if (result == -1) {\r
790     status = NV_FAIL_S;\r
791   }\r
792   else status = NV_DONE_S;\r
793 \r
794   if (status == NV_DONE_S) {\r
795     nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version;\r
796     nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.valid;\r
797   }\r
798   else {\r
799     nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = NV_PRL_VERSION_INVALID;\r
800     nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = FALSE;\r
801   }\r
802 \r
803   return status;\r
804 } /* nvio_read_roaming_list */\r
805 #endif\r
806 \r
807 \r
808 \f\r
809 /*===========================================================================\r
810 \r
811 FUNCTION NVIO_READ\r
812 \r
813 DESCRIPTION\r
814   This procedure processes NVM read requests.  It checks to make sure\r
815   that a valid item has been requested, it reads the NVM item using EFS\r
816   services and it performs the translation from internal NVM format to\r
817   external format. If the item being read requires no special processing,\r
818   it is passed on to nvimio_io().\r
819 \r
820 DEPENDENCIES\r
821   None.\r
822 \r
823 RETURN VALUE\r
824   Status of read operation.\r
825 \r
826 SIDE EFFECTS\r
827   None.\r
828 \r
829 ===========================================================================*/\r
830 \r
831 nv_stat_enum_type \r
832 nvio_read (\r
833   nv_cmd_ext_type  *cmd_ext_ptr           /* Pointer to Command block */\r
834 )\r
835 {\r
836   nv_stat_enum_type status;  /* Status to return to calling procedure */\r
837   dword   local_esn_chksum;    /* buffer for esn chksum */\r
838   dword   local_esn;\r
839   uint16  array_size;\r
840   byte index; /* Specific index of an array */\r
841 #ifdef FEATURE_NV_SFS_PRIVATE\r
842   sfs_priv_errno_enum_type sfs_ret = 0;\r
843 #endif\r
844 \r
845 #ifdef FEATURE_NV_SUPPORT_FLASH_OTP\r
846   FlashOTP_ReturnType otp_ret_val;\r
847   FlashOTP_ProtectOp_ReturnType otp_prot_ret_val;\r
848   byte  local_imei[NV_UE_IMEI_SIZE];\r
849   int i;\r
850 #endif\r
851  \r
852 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
853 \r
854   /* If item code is out of range return with bad parameter status. */\r
855 \r
856   if (cmd_ext_ptr->nvcmd->item >= NV_MAX_I) {\r
857     return NV_BADPARM_S;\r
858   }\r
859   else {                 \r
860 \r
861 #ifdef FEATURE_NV_RUIM\r
862 \r
863     /* If the R-UIM supports the item,\r
864      * return the status else use "regular" NVM.\r
865      */\r
866     if (cmd_ext_ptr->context == 0) {\r
867       if ( nvruim_read(cmd_ext_ptr->nvcmd, &status) == NV_RUIM_SUPPORTS_ITEM ){\r
868         if (cmd_ext_ptr->nvcmd->item == NV_ROAMING_LIST_683_I) \r
869         {\r
870           if (status == NV_DONE_S) {\r
871             nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version;\r
872             nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.valid;\r
873           }\r
874           else {\r
875             nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = NV_PRL_VERSION_INVALID;\r
876             nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = FALSE;\r
877           }\r
878         }\r
879       return status;\r
880       }\r
881     }\r
882 #ifdef FEATURE_DUAL_STANDBY\r
883     else {\r
884       if ( nvruim_read_ext(cmd_ext_ptr, &status) == NV_RUIM_SUPPORTS_ITEM ){\r
885         if (cmd_ext_ptr->nvcmd->item == NV_ROAMING_LIST_683_I) \r
886         {\r
887           if (status == NV_DONE_S) {\r
888             nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version;\r
889             nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = cmd_ext_ptr->nvcmd->data_ptr->roaming_list.valid;\r
890           }\r
891           else {\r
892             nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = NV_PRL_VERSION_INVALID;\r
893             nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] = FALSE;\r
894           }\r
895         }\r
896         return status;\r
897       }\r
898     }\r
899 #endif\r
900 #endif\r
901 \r
902     switch (cmd_ext_ptr->nvcmd->item) {\r
903 \r
904     /* read up data item, do special processing if required */\r
905 \r
906 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
907       /* This item is a special case for writes, so it has no generic path in\r
908        * nvimio_io(). Thus we have to handle the read of this item specially. \r
909        */\r
910       case NV_ESN_I:\r
911 \r
912         status = nvio_read_item(NV_ESN_I,/* file handle */\r
913                                 0,\r
914                                 (byte *)&cmd_ext_ptr->nvcmd->data_ptr->esn, /* data ptr */\r
915                                 sizeof(nvi_item.esn),/* data count */\r
916                                 cmd_ext_ptr->context); /* SIM context */\r
917         break; \r
918 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
919 \r
920       /* Since NV_ESN_ME is a shadow variable for ESN in EFS, return the value \r
921          of ESN in EFS.\r
922        */\r
923 \r
924       case NV_ESN_ME_I:\r
925 \r
926         status = nvio_read_item(NV_ESN_I,/* file handle */\r
927                                 0,\r
928                                 (byte *)&cmd_ext_ptr->nvcmd->data_ptr->esn_me, /* data ptr */\r
929                                 sizeof(nvi_item.esn), /* data count */\r
930                                 cmd_ext_ptr->context); /* SIM context */\r
931 \r
932         break; \r
933 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
934 \r
935      /* ESN checksum read returns the status of */\r
936      /* the checksum, NOT the checksum itself.  */\r
937 \r
938       case NV_ESN_CHKSUM_I:\r
939 \r
940         /* First read the ESN itself into a local buffer. */\r
941         status = nvio_read_item(NV_ESN_I,/* file handle */\r
942                                 0,\r
943                                 (byte*)&local_esn,          /* data ptr */\r
944                                 sizeof(local_esn),  /* data count */\r
945                                 cmd_ext_ptr->context); /* SIM context */\r
946 \r
947         if(status != NV_DONE_S)\r
948           break;\r
949 \r
950         /* Next read the ESN checksum into a local buffer. */\r
951         status = nvio_read_item(NV_ESN_CHKSUM_I,   /* file handle */\r
952                                 0,\r
953                                 &local_esn_chksum,   /* data ptr */\r
954                                 sizeof(local_esn_chksum), /* data count */\r
955                                 cmd_ext_ptr->context); /* SIM context */\r
956 \r
957         if(status != NV_DONE_S) \r
958           break;\r
959         /* Next compute the ESN checksum and compare against  */\r
960         /* the stored checksum.  Return its status to caller. */\r
961 \r
962         if (crc_30_calc((byte *)&local_esn,\r
963                         sizeof(local_esn) * 8) == local_esn_chksum) {\r
964           cmd_ext_ptr->nvcmd->data_ptr->esn_chksum.chksum = NV_VALID_ESN_CHKSUM;\r
965         } \r
966         else {\r
967           cmd_ext_ptr->nvcmd->data_ptr->esn_chksum.chksum = ~NV_VALID_ESN_CHKSUM;\r
968         }\r
969         status = NV_DONE_S;\r
970         break;\r
971 \r
972 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
973 \r
974       /* Since NV_MEID_ME is a shadow variable for MEID in EFS, return the value \r
975          of MEID in EFS.\r
976        */\r
977 \r
978       case NV_MEID_ME_I:\r
979 \r
980         status = nvio_read_item(NV_MEID_I,/* file handle */\r
981                                 0,\r
982                                 (byte *)cmd_ext_ptr->nvcmd->data_ptr, /* data ptr */\r
983                                 nvim_op_get_size(cmd_ext_ptr->nvcmd->item),/* data count */\r
984                                 cmd_ext_ptr->context); /* SIM context */\r
985         break; \r
986 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
987 \r
988 #ifdef FEATURE_NV_SUPPORT_FLASH_OTP\r
989 \r
990       case NV_UE_IMEI_I:\r
991 \r
992         /* Check whether OTP area is programmed */\r
993         otp_prot_ret_val = flash_otp_status();\r
994 \r
995         /* If the protection is not active, then return NV data */\r
996         if ((otp_prot_ret_val == FLASH_OTP_PROTECTION_INACTIVE) ||\r
997             (otp_prot_ret_val == FLASH_OTP_NOT_SUPPORTED)) {\r
998           /* Read from NV */\r
999           status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1000                                   0,\r
1001                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1002                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1003                                   cmd_ext_ptr->context); /* SIM context */\r
1004           return status;\r
1005         }\r
1006         else {\r
1007           /* Read from OTP Area */\r
1008           otp_ret_val = flash_otp_operation(FLASH_OTP_OP_IMEI_READ,\r
1009                                           (uint8 *)local_imei);\r
1010 \r
1011           if (otp_ret_val != FLASH_OTP_IO_SUCCESS) {\r
1012              QSR_MSG_HIGH ( 2233670895ULL, "OTP Read failure",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1013              status = NV_FAIL_S;\r
1014              return status;\r
1015           }\r
1016           /* Read from NV */\r
1017           status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1018                                   0,\r
1019                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1020                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1021                                   cmd_ext_ptr->context); /* SIM context */\r
1022 \r
1023           if ( (status != NV_DONE_S) && (status != NV_NOTACTIVE_S) ) {\r
1024             QSR_MSG_HIGH ( 3750100468ULL, "NV Read failure for IMEI",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1025             return status;\r
1026           }\r
1027 \r
1028           /* If the IMEI got wiped out, then set it from OTP area */\r
1029           if ( status == NV_NOTACTIVE_S )\r
1030           {\r
1031             for (i=0; i<NV_UE_IMEI_SIZE; i++)\r
1032               cmd_ext_ptr->nvcmd->data_ptr->ue_imei.ue_imei[i] = local_imei[i];\r
1033 \r
1034             status = nvio_write(cmd_ext_ptr);\r
1035 \r
1036             /* Turn back on permanent file attribute */\r
1037             if (status == NV_DONE_S) {\r
1038               QSR_MSG_HIGH ( 2227689700ULL, "IMEI successfully propagated from OTP to NV.",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1039               return status;\r
1040             }\r
1041 \r
1042             QSR_MSG_HIGH ( 2226192909ULL, "IMEI could not propagate from OTP to NV.",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1043             return (NV_FAIL_S);\r
1044           }\r
1045 \r
1046           /* Compare the contents of OTP and NV */\r
1047           if (memcmp(local_imei, (byte *)cmd_ext_ptr->nvcmd->data_ptr->ue_imei.ue_imei,\r
1048                      sizeof(local_imei))==0)\r
1049           {\r
1050             /* Do nothing */\r
1051             QSR_MSG_HIGH ( 847005925ULL, "OTP and NV contents are same.",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1052             return status;\r
1053           }\r
1054           else\r
1055           {\r
1056             /* Return Failure */\r
1057             QSR_MSG_HIGH ( 3216026684ULL, "IMEI does not match between OTP and NV",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
1058             return (NV_FAIL_S);\r
1059           }\r
1060         }\r
1061         break;\r
1062 \r
1063 #elif defined (FEATURE_NV_SFS_PRIVATE)\r
1064 \r
1065       case NV_UE_IMEI_I:\r
1066         sfs_ret = sfs_priv_imei_read((uint8 *)cmd_ext_ptr->nvcmd->data_ptr,\r
1067                                      nvim_op_get_size(cmd_ext_ptr->nvcmd->item));\r
1068         if(sfs_ret == SFS_PRIV_INACTIVE) \r
1069         {\r
1070           return NV_NOTACTIVE_S;\r
1071         }\r
1072         else if(sfs_ret == SFS_PRIV_SUCCESS) \r
1073         {\r
1074           return NV_DONE_S;\r
1075         }\r
1076         else\r
1077         {\r
1078           return NV_FAIL_S;\r
1079         }\r
1080 \r
1081 #else\r
1082       case NV_UE_IMEI_I:\r
1083         status =  nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1084                                  0,\r
1085                                  (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1086                                  nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1087                                  cmd_ext_ptr->context);\r
1088 #endif\r
1089         break;\r
1090 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1091 \r
1092       /* This item is a special case for writes, so it has no generic path in\r
1093        * nvimio_io(). Thus we have to handle the read of this item here \r
1094        * rather than in nvimio_io().\r
1095        */\r
1096       case NV_VERNO_MAJ_I:\r
1097         status = nvio_read_item(cmd_ext_ptr->nvcmd->item, /* item ID */\r
1098                               0,\r
1099                               (byte*)&cmd_ext_ptr->nvcmd->data_ptr->verno_maj, /* data ptr */\r
1100                               sizeof(nvi_item.verno_maj), /* data count */\r
1101                               cmd_ext_ptr->context); /* context */\r
1102         break;\r
1103 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1104 \r
1105       /* This item is a special case for writes, so it has no generic path in\r
1106        * nvimio_io(). Thus we have to handle the read of this item here \r
1107        * rather than in nvimio_io().\r
1108        */\r
1109       case NV_VERNO_MIN_I:\r
1110         status = nvio_read_item(NV_VERNO_MIN_I,  /* item ID */\r
1111                               0,\r
1112                               (byte*)&cmd_ext_ptr->nvcmd->data_ptr->verno_min, /* data ptr */\r
1113                               sizeof(nvi_item.verno_min), /* data count */\r
1114                               cmd_ext_ptr->context);  /* context */\r
1115         break;\r
1116 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1117       /* Some invariant offset items are handled as a special case,\r
1118          because they will always have a valid entry, but if their \r
1119          feature is not turned on, then you can't read, write or build\r
1120          them */\r
1121       case NV_PAP_PASSWORD_I:\r
1122         #ifdef NV_FEATURE_PAP\r
1123           status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1124                                   0,\r
1125                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1126                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1127                                   cmd_ext_ptr->context);\r
1128         #else\r
1129           status = NV_BADPARM_S;\r
1130         #endif\r
1131         break;        \r
1132 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1133       case NV_UP_KEY_I:\r
1134         #ifdef NV_FEATURE_UP\r
1135           index = *((byte *)cmd_ext_ptr->nvcmd->data_ptr);\r
1136           if (index >= NV_UP_LINK_INFO_TABLE_SIZE)\r
1137             status = NV_BADPARM_S;\r
1138           else\r
1139             status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1140                                     index,\r
1141                                     ((byte *)cmd_ext_ptr->nvcmd->data_ptr)+sizeof(index),\r
1142                                     nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1143                                     cmd_ext_ptr->context);\r
1144         #else\r
1145           status = NV_BADPARM_S;\r
1146         #endif\r
1147         break;\r
1148 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1149       case NV_BD_ADDR_I:\r
1150         #if (defined(FEATURE_BT) || defined(FEATURE_BT_QSOC))\r
1151           status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1152                                   0,\r
1153                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1154                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1155                                   cmd_ext_ptr->context);\r
1156         #else\r
1157           status = NV_BADPARM_S;\r
1158         #endif\r
1159         break;\r
1160 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1161 \r
1162       case NV_DIAL_I:\r
1163         status = nvio_read_dial(NV_DIAL_I,\r
1164                                 NV_MAX_SPEED_DIALS,\r
1165                                 cmd_ext_ptr->nvcmd->data_ptr->dial.address,\r
1166                                 &cmd_ext_ptr->nvcmd->data_ptr->dial,\r
1167                                 cmd_ext_ptr->context);\r
1168         break;\r
1169 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1170 \r
1171       case NV_STACK_I:\r
1172         status = nvio_read_stdial(NV_STACK_I,\r
1173                                   NV_MAX_STACK_DIALS,\r
1174                                   cmd_ext_ptr->nvcmd->data_ptr->stack.address,\r
1175                                   &cmd_ext_ptr->nvcmd->data_ptr->stack,\r
1176                                   cmd_ext_ptr->context);\r
1177         break;\r
1178 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1179 \r
1180 #ifdef NV_FEATURE_REDIAL\r
1181       case NV_REDIAL_I:\r
1182         status = nvio_read_dial(NV_DIAL_I,\r
1183                                 NV_MAX_SPEED_DIALS + NVI_REDIAL_EXTENSIONS,\r
1184                                 NV_MAX_SPEED_DIALS,\r
1185                                 &cmd_ext_ptr->nvcmd->data_ptr->dial,\r
1186                                 cmd_ext_ptr->context);\r
1187         break;\r
1188 #endif\r
1189 \r
1190 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1191 \r
1192       case NV_SMS_I:\r
1193       case NV_SMS_DM_I:\r
1194         status = nvio_read_sms(cmd_ext_ptr);\r
1195         break;\r
1196 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1197 \r
1198 #ifdef NV_FEATURE_RENTAL_ITEMS\r
1199 #error code not present\r
1200 #endif\r
1201 \r
1202 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1203 \r
1204 #ifdef NV_FEATURE_RENTAL_ITEMS\r
1205 #error code not present\r
1206 #endif\r
1207 \r
1208 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1209 \r
1210 #ifdef NV_FEATURE_FACTORY_INFO\r
1211       case NV_FACTORY_INFO_I:  \r
1212         /* Copy from the static block, latest factory data */\r
1213         memcpy((void *) cmd_ext_ptr->nvcmd->data_ptr->fact_info,\r
1214                fact_data, \r
1215                (word) NV_FACTORY_INFO_SIZ);\r
1216         status = NV_DONE_S;\r
1217         break;\r
1218 #endif\r
1219 \r
1220 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1221 \r
1222 #ifdef NV_FEATURE_PRL_ITEMS\r
1223   #ifdef NV_FEATURE_IS683A_PRL\r
1224       case NV_ROAMING_LIST_683_I:\r
1225   #else\r
1226       case NV_ROAMING_LIST_I:\r
1227   #endif\r
1228       status = nvio_read_roaming_list(cmd_ext_ptr);\r
1229       break;\r
1230 #endif\r
1231 \r
1232 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1233 \r
1234 #ifdef FEATURE_NV_SUPPORT_FLASH_OTP\r
1235       case NV_DEVICE_SERIAL_NO_I:\r
1236          if (flash_otp_operation(FLASH_OTP_OP_SERIALNO_READ,\r
1237                        (byte *)cmd_ext_ptr->nvcmd->data_ptr) != FLASH_OTP_IO_SUCCESS) {\r
1238            return NV_FAIL_S;\r
1239          }\r
1240          else {\r
1241            return NV_DONE_S;\r
1242          }\r
1243 #endif\r
1244 \r
1245 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1246 \r
1247 #ifdef FEATURE_GWSMS\r
1248       case NV_SMS_GW_I:\r
1249         status = nvio_read_sms_gw(cmd_ext_ptr);\r
1250         break;\r
1251 #endif\r
1252 \r
1253       default:\r
1254 \r
1255         /* Check if there's an actual entry */\r
1256         if (nvim_op_get_presence(cmd_ext_ptr->nvcmd->item)) {\r
1257           array_size = nvim_op_get_array_size(cmd_ext_ptr->nvcmd->item);\r
1258           if (array_size == 0)  /* If not an array, 1 means an array of 1 */\r
1259             status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1260                                   0,\r
1261                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
1262                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1263                                   cmd_ext_ptr->context);\r
1264           else /* More than one item */ {\r
1265             index = *((byte *) cmd_ext_ptr->nvcmd->data_ptr);\r
1266             if (index >= array_size) {\r
1267               status = NV_BADPARM_S;\r
1268             }\r
1269             else {\r
1270               status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
1271                                     index,\r
1272                                     ((byte *)cmd_ext_ptr->nvcmd->data_ptr)+sizeof(index),\r
1273                                     nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1274                                     cmd_ext_ptr->context);\r
1275             }\r
1276           }\r
1277         }\r
1278         else  /* Not a valid entry */ {\r
1279           QSR_MSG_HIGH( 253627890ULL, "nvio_read item %d not for this target", cmd_ext_ptr->nvcmd->item, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1280           status = NV_BADPARM_S;\r
1281         }\r
1282     /* End read switch and return status. */\r
1283     } /* switch */\r
1284 \r
1285     return status;\r
1286   } /* else */\r
1287 } /* nvio_read */\r
1288 \r
1289 \f\r
1290 /*===========================================================================\r
1291 \r
1292 FUNCTION NVIO_TRANSLATE_TO_INTERNAL\r
1293 \r
1294 DESCRIPTION\r
1295   This function translates a digit frome external representation to\r
1296   internal 4 bit NVM storage representation.\r
1297 \r
1298 DEPENDENCIES\r
1299   None.\r
1300 \r
1301 RETURN VALUE\r
1302   The 4 bit digit value.\r
1303 \r
1304 SIDE EFFECTS\r
1305   None.\r
1306 \r
1307 ===========================================================================*/\r
1308 \r
1309 static byte \r
1310 nvio_translate_to_internal ( \r
1311   byte   digit    /* External digit representation */\r
1312 )\r
1313 {\r
1314   if ((digit >= '0') && (digit <= '9')) return(digit - '0');\r
1315   else if (digit == '*' ) return(0x0A);\r
1316   else if (digit == '#' ) return(0x0B);\r
1317   else if (digit == '-' ) return(0x0C);\r
1318   else if (digit == 'P' ) return(0x0D);\r
1319   else if (digit == 'T' ) return(0x0E);\r
1320   else if (digit == 'L' ) return(0x0F);\r
1321   else {\r
1322     ERR("Illegal dial digit",0,0,0);\r
1323     return(0x0C);\r
1324   }\r
1325 \r
1326 } /* nvio_translate_to_internal */\r
1327 \r
1328 \f\r
1329 /********************** TEMPORARY ******************************************/\r
1330 /************* Remove this function after cross-update is removed **********/\r
1331 /*===========================================================================\r
1332 \r
1333 FUNCTION NVT_TRANSLATE_TO_EXTERNAL\r
1334 \r
1335 DESCRIPTION\r
1336   This function translates a digit frome internal 4 bit NVM storage\r
1337   to external 8 bit ASCII representation.\r
1338 \r
1339 DEPENDENCIES\r
1340   None.\r
1341 \r
1342 RETURN VALUE\r
1343   The 8 bit ASCII digit value.\r
1344 \r
1345 SIDE EFFECTS\r
1346   None.\r
1347 \r
1348 ===========================================================================*/\r
1349 \r
1350 static byte nvt_translate_to_external\r
1351\r
1352   byte   digit    /* Internal digit representation */\r
1353 )\r
1354 {\r
1355   if ((digit > 0) && (digit <= 0x09)) return(digit + '0');\r
1356   else if (digit == 0x0A) return('0');\r
1357   else if (digit == 0x0B) return('*');\r
1358   else if (digit == 0x0C) return('#');\r
1359   else return(' ');\r
1360 \r
1361 } /* nvt_translate_to_external */\r
1362 /********************** TEMPORARY ******************************************/\r
1363 \r
1364 \f\r
1365 /*===========================================================================\r
1366 \r
1367 FUNCTION NVT_TRANSLATE_TO_INTERNAL\r
1368 \r
1369 DESCRIPTION\r
1370   This function translates a digit frome external representation to\r
1371   internal 4 bit NVM storage representation.\r
1372 \r
1373 DEPENDENCIES\r
1374   None.\r
1375 \r
1376 RETURN VALUE\r
1377   The 4 bit digit value.\r
1378 \r
1379 SIDE EFFECTS\r
1380   None.\r
1381 \r
1382 ===========================================================================*/\r
1383 \r
1384 static byte \r
1385 nvt_translate_to_internal ( \r
1386   byte   digit    /* External digit representation */\r
1387 )\r
1388 {\r
1389   if ((digit > '0') && (digit <= '9')) return(digit - '0');\r
1390   else if (digit == '0') return(0x0A);\r
1391   else if (digit == '*') return(0x0B);\r
1392   else if (digit == '#') return(0x0C);\r
1393   else return(0x0F);\r
1394 \r
1395 } /* nvt_translate_to_internal */\r
1396 \f\r
1397 /*===========================================================================\r
1398 \r
1399 FUNCTION NVIO_WRITE_ITEM\r
1400 \r
1401 DESCRIPTION\r
1402   This function writes an NV item to NV database.\r
1403 \r
1404 DEPENDENCIES\r
1405   None.\r
1406 \r
1407 RETURN VALUE\r
1408   NV_DONE_S if it worked\r
1409   Or the failure status from the lower levels.\r
1410 \r
1411 SIDE EFFECTS\r
1412 \r
1413 ===========================================================================*/\r
1414 nv_stat_enum_type \r
1415 nvio_write_item ( \r
1416   nv_items_enum_type    item,\r
1417   byte   index,\r
1418   void   * data_ptr,\r
1419   uint32 item_size,\r
1420   uint16     context\r
1421\r
1422 {\r
1423   int               return_size;\r
1424   boolean           item_present;\r
1425   char              f_name[120];\r
1426   nv_stat_enum_type status;\r
1427   struct fs_stat    temp_buf;\r
1428 \r
1429 \r
1430   item_present = nvim_op_get_presence(item);\r
1431 \r
1432   if(item_present) {\r
1433     /* Creating file name for array item*/\r
1434     /* Check if context is defined*/\r
1435     if (context == 0) { /* Context is not defined, use old pathnames*/\r
1436     if(index == 0)\r
1437       (void)snprintf(f_name,sizeof(f_name),"/nvm/num/%d",item);  \r
1438     else\r
1439       (void)snprintf(f_name,sizeof(f_name),"/nvm/num/%d_%d",item,index);\r
1440     }\r
1441 \r
1442     else { /* Context is defined. Use context for creating pathname*/\r
1443       if(index == 0)\r
1444         (void)snprintf(f_name,sizeof(f_name),"/nvm/context%d/%d",context,item);\r
1445       else\r
1446         (void)snprintf(f_name,sizeof(f_name),"/nvm/context%d/%d_%d",context,item,index);\r
1447     }\r
1448     /* Check if the file is present or not. */\r
1449     if(efs_stat(f_name,&temp_buf) != -1) {\r
1450       if((temp_buf.st_size) != (nvim_op_get_size(item))) {\r
1451         (void)efs_unlink(f_name);\r
1452       }\r
1453     }\r
1454 \r
1455     return_size = efs_put(f_name, data_ptr, item_size, \r
1456                           O_CREAT|O_AUTODIR, 0777);\r
1457     if(return_size >= 0)\r
1458       status = NV_DONE_S;\r
1459     else\r
1460       status = NV_FAIL_S;\r
1461   }\r
1462   else {\r
1463     ERR("nvio_write %d not for this target", (int)item, 0, 0);\r
1464     status = NV_BADPARM_S;  \r
1465   }\r
1466   return status;\r
1467 } /* End of nvio_write_item*/\r
1468 \r
1469 \f    \r
1470 /*===========================================================================\r
1471 \r
1472 FUNCTION NVIO_WRITE_ESN\r
1473 \r
1474 DESCRIPTION\r
1475   This function processed a write command to the NV_ESN_I item.\r
1476 \r
1477 DEPENDENCIES\r
1478   None.\r
1479 \r
1480 RETURN VALUE\r
1481   NV_DONE_S if it worked error status code if it failed. \r
1482 \r
1483 SIDE EFFECTS\r
1484   None\r
1485 \r
1486 ===========================================================================*/\r
1487 \r
1488 LOCAL nv_stat_enum_type \r
1489 nvio_write_esn(\r
1490   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
1491 )\r
1492 {\r
1493   nv_stat_enum_type status;   /* Function return value */\r
1494   dword local_esn;            /* tmp buffer for esn */\r
1495   dword local_esn_chksum;     /**/                                  \r
1496   /* Read the current ESN value */\r
1497   status = nvio_read_item(NV_ESN_I,/* file handle */\r
1498                          0,\r
1499                          &local_esn,          /* data ptr */\r
1500                          sizeof(local_esn), /* data count */\r
1501                          cmd_ext_ptr->context ); /* Context */\r
1502         \r
1503   if (status == NV_FAIL_S){\r
1504     return status;\r
1505   }\r
1506         \r
1507   /* The ESN may only be written once */\r
1508   if ((local_esn != 0) &&\r
1509       (local_esn != 0xFFFFFFFF) && (status != NV_NOTACTIVE_S)){\r
1510     /* The file is now considered read-only */\r
1511     return NV_READONLY_S;\r
1512   }\r
1513 \r
1514   /* Write the ESN, the ESN checksum, and the ESN valid flag. */\r
1515   status = nvio_write_item(NV_ESN_I,  /* Item name */\r
1516                           0, /* index */\r
1517                           (byte*)&cmd_ext_ptr->nvcmd->data_ptr->esn, /* data ptr */\r
1518                           sizeof(nvi_item.esn), /* data count */\r
1519                           cmd_ext_ptr->context);  /* context */\r
1520 \r
1521   if (status == NV_DONE_S)\r
1522   {\r
1523     local_esn_chksum = crc_30_calc((byte *)&cmd_ext_ptr->nvcmd->data_ptr->esn,\r
1524                                       sizeof(nvi_item.esn) * 8);\r
1525 \r
1526     status = nvio_write_item(NV_ESN_CHKSUM_I,  /* file handle */\r
1527                             0, /* file position */\r
1528                             (byte*)&local_esn_chksum, /* data ptr */\r
1529                             sizeof(local_esn_chksum), /* data count */\r
1530                             cmd_ext_ptr->context);  /* context */\r
1531   }\r
1532         \r
1533   return status;\r
1534 } /* nvio_write_esn */\r
1535 \r
1536 \f\r
1537 /*===========================================================================\r
1538 \r
1539 FUNCTION NVIO_WRITE_ROAMING_LIST\r
1540 \r
1541 DESCRIPTION\r
1542   This function writes the roaming list. Handled as a special case in the \r
1543   item manager.\r
1544 \r
1545 DEPENDENCIES\r
1546   None.\r
1547 \r
1548 RETURN VALUE\r
1549   NV_DONE_S    if it worked\r
1550   NV_BADPARM_S if requested bytes are out of range for NVM\r
1551 \r
1552 SIDE EFFECTS\r
1553   None\r
1554 \r
1555 ===========================================================================*/\r
1556 \r
1557 LOCAL nv_stat_enum_type \r
1558 nvio_write_roaming_list (\r
1559   nv_cmd_ext_type  *cmd_ext_ptr\r
1560 )\r
1561 {\r
1562   word               item_size;   /* Size of item (in bytes) */\r
1563   nv_stat_enum_type  status;      /* Function return value */  \r
1564   int                fd;\r
1565   char               f_name[120];\r
1566   fs_ssize_t         result = 0;\r
1567   fs_size_t          nbytes;\r
1568   fs_size_t          bytes_written;\r
1569   char               *write_buf;\r
1570   boolean            true_flag   = TRUE;\r
1571   \r
1572   /* Check for illegal NAM */\r
1573   if(cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam >= NV_MAX_NAMS)\r
1574   {\r
1575     return NV_BADPARM_S;\r
1576   }\r
1577 \r
1578 \r
1579   /* Get its size */\r
1580   item_size = NV_ROAMING_LIST_HEADER_SIZE +\r
1581                  nv_max_size_of_roaming_list();\r
1582 \r
1583   QSR_MSG_MED( 2779538831ULL, "size: %d", item_size, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1584 \r
1585   /* Construct pathname*/\r
1586   if (cmd_ext_ptr->context == 0) /* No context defined */\r
1587     snprintf(f_name,sizeof(f_name),"/nvm/prl_%d",\r
1588              cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam);\r
1589   else\r
1590     snprintf(f_name,sizeof(f_name),"/nvm/context%d/prl_%d",\r
1591              cmd_ext_ptr->context,cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam);\r
1592 \r
1593   fd = efs_open(f_name, O_RDWR | O_CREAT , 0777 );\r
1594 \r
1595   /* nbytes should be one less than item_size as the write_buf is pointing to \r
1596    * prl_version which is second element of the prl data structure and NAM \r
1597    * is not supposed to be updated */\r
1598   nbytes = item_size - 1;\r
1599   bytes_written = 0;\r
1600 \r
1601   /*\r
1602   memcpy(((byte*)write_buf), &true_flag, sizeof(true_flag));\r
1603   memcpy(((byte*)write_buf)+sizeof(true_flag), \r
1604          (byte*)&(cmd_ext_ptr->data_ptr->roaming_list.prl_version),\r
1605          item_size-sizeof(true_flag));\r
1606 */\r
1607 \r
1608   write_buf = (void *)&(cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version);\r
1609 \r
1610   efs_write (fd,\r
1611              (const void *) &(true_flag),\r
1612              sizeof(true_flag));\r
1613 \r
1614   efs_lseek(fd, sizeof(true_flag), SEEK_CUR);\r
1615 \r
1616   while (bytes_written < nbytes) {\r
1617     result = efs_write (fd,\r
1618                         (const void *) (write_buf + bytes_written),\r
1619                         nbytes - bytes_written);\r
1620     if (result <= 0)\r
1621       break;\r
1622     bytes_written += (fs_size_t) result;\r
1623   }\r
1624   \r
1625   if (result == -1) {\r
1626     status = NV_FAIL_S;\r
1627   }\r
1628   else\r
1629     status = NV_DONE_S;\r
1630 \r
1631   nv_prl_version_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] =\r
1632           cmd_ext_ptr->nvcmd->data_ptr->roaming_list.prl_version;\r
1633   nv_prl_valid_data[cmd_ext_ptr->nvcmd->data_ptr->roaming_list.nam] =\r
1634           cmd_ext_ptr->nvcmd->data_ptr->roaming_list.valid;\r
1635 \r
1636   efs_close(fd);\r
1637   return status;\r
1638 }  /* nvio_write_roaming_list */\r
1639 \r
1640 \r
1641 \f\r
1642 /*===========================================================================\r
1643 \r
1644 FUNCTION NVIO_WRITE_DIAL\r
1645 \r
1646 DESCRIPTION\r
1647   This function processes write requests for speed dial number.  It performs\r
1648   translations necessary from external to internal format and then attempts\r
1649   to write the NVM item using EFS services.\r
1650 \r
1651 DEPENDENCIES\r
1652   None.\r
1653 \r
1654 RETURN VALUE\r
1655   Status of write operation.\r
1656 \r
1657 SIDE EFFECTS\r
1658   None.\r
1659 \r
1660 ===========================================================================*/\r
1661 \r
1662 LOCAL nv_stat_enum_type \r
1663 nvio_write_dial (\r
1664   nv_items_enum_type    item,             /* Item to access */\r
1665   byte                  index_range,      /* Maximum allowed range for index */\r
1666   byte                  index,            /* speed dial # */\r
1667   nv_dial_type          *dial_ptr,        /* Pointer to write source buffer */\r
1668   byte                  item_context      /* Context of item in NV */\r
1669 )\r
1670 {\r
1671   word               i;                   /* Index through speed dial numbers */\r
1672   byte               ndigits;             /* # of digits to process */\r
1673   \r
1674 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1675 \r
1676   /* Check for illegal offset into the array */\r
1677   if (index >= index_range) return NV_BADPARM_S;\r
1678 \r
1679   /* First copy the digits count from external buffer to internal */\r
1680   /* buffer, making sure that only the maximum number allowed can */\r
1681   /* be stored.  When copying translate digits to internal type.  */\r
1682 \r
1683   nvi_item.dial.num_digits = MIN(dial_ptr->num_digits, NV_MAX_DIAL_DIGITS);\r
1684   ndigits = nvi_item.dial.num_digits;\r
1685   for (i = 0; i < ndigits; i++) {\r
1686 \r
1687     /* Copy the digits, compressing from one digit per byte into two */\r
1688     /* digits per byte.  Even bytes are stored in least significant  */\r
1689     /* digit, odd bytes in most significant digit.                   */\r
1690 \r
1691     if ((i%2) == 0) {\r
1692       nvi_item.dial.digits[i/2] = \r
1693          nvio_translate_to_internal(dial_ptr->digits[i]);\r
1694     } else {\r
1695       nvi_item.dial.digits[i/2] |= \r
1696          (byte)(nvio_translate_to_internal(dial_ptr->digits[i]) << 4);\r
1697     }\r
1698   } /* for */\r
1699 \r
1700   /* Copy the name to internal type. */\r
1701     (void)memcpy((void *) nvi_item.dial.letters, (void *) dial_ptr->letters,\r
1702                   NV_MAX_LTRS);\r
1703 \r
1704 #ifdef NV_FEATURE_EXTENDED_UI\r
1705   nvi_item.dial.status = dial_ptr->status;\r
1706 #endif\r
1707 \r
1708   /* Write out item. */\r
1709   return  nvio_write_item(\r
1710                                   item,\r
1711                                   index,\r
1712 #ifdef NV_FEATURE_EXTENDED_UI\r
1713                                   (byte*)&nvi_item.dial.status,     \r
1714 #else\r
1715                                   (byte*)&nvi_item.dial.num_digits, \r
1716 #endif\r
1717                                   sizeof(nvi_item.dial),\r
1718                                   item_context);\r
1719 \r
1720 } /* nvio_write_dial */\r
1721 \r
1722 \f\r
1723 /*===========================================================================\r
1724 \r
1725 FUNCTION NVIO_WRITE_STDIAL\r
1726 \r
1727 DESCRIPTION\r
1728   This function processes write requests for stack dial number.  It performs\r
1729   translations necessary from external to internal format and then attempts\r
1730   to write the NV item using EFS services.\r
1731 \r
1732 DEPENDENCIES\r
1733   None.\r
1734 \r
1735 RETURN VALUE\r
1736   Status of write operation.\r
1737 \r
1738 SIDE EFFECTS\r
1739   None.\r
1740 \r
1741 ===========================================================================*/\r
1742 \r
1743 LOCAL nv_stat_enum_type \r
1744 nvio_write_stdial (\r
1745   nv_items_enum_type    item,        /* Item to access */\r
1746   byte                  index_range, /* Maximum allowed range for index */\r
1747   byte                  index,       /* speed dial # */\r
1748   nv_stdial_type        *dial_ptr,   /* Pointer to external write source buffer */\r
1749   byte                  item_context /* Context of item in NV */\r
1750 )\r
1751 {\r
1752   word                  i;           /* Index through stack dial numbers */\r
1753 \r
1754 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
1755 \r
1756   /* Check if the index is within the range */\r
1757   if (index >= index_range) return NV_BADPARM_S;\r
1758   \r
1759   /* First copy the digits count from external buffer to internal */\r
1760   /* buffer, making sure that only the maximum number allowed can */\r
1761   /* be stored.  When copying translate digits to internal type.  */\r
1762 \r
1763   nvi_item.stack.num_digits = MIN(dial_ptr->num_digits, NV_MAX_DIAL_DIGITS);\r
1764   for (i = 0; i < nvi_item.stack.num_digits; i++) {\r
1765 \r
1766     /* Copy the digits, compressing from one digit per byte into two */\r
1767     /* digits per byte.  Even bytes are stored in least significant  */\r
1768     /* digit, odd bytes in most significant digit.                   */\r
1769 \r
1770     if ((i%2) == 0) {\r
1771       nvi_item.stack.digits[i/2] = nvio_translate_to_internal(dial_ptr->digits[i]);\r
1772     } else {\r
1773       nvi_item.stack.digits[i/2] |= (byte)(nvio_translate_to_internal(dial_ptr->digits[i]) << 4);\r
1774     }\r
1775   } /* for */\r
1776 \r
1777   /* Copy the name to internal type. */\r
1778   (void)memcpy((void *) nvi_item.stack.letters, (void *) dial_ptr->letters,\r
1779                 NV_MAX_LTRS);\r
1780 \r
1781 #ifdef NV_FEATURE_EXTENDED_UI\r
1782   nvi_item.stack.status = dial_ptr->status;\r
1783   nvi_item.stack.time_stamp = dial_ptr->time_stamp;\r
1784   nvi_item.stack.duration = dial_ptr->duration;\r
1785 #endif\r
1786 \r
1787   /* Write out item. */\r
1788   return nvio_write_item(\r
1789                                  item,\r
1790                                  index,\r
1791 #ifdef NV_FEATURE_EXTENDED_UI\r
1792                                  (byte*)&nvi_item.stack.status,\r
1793 #else\r
1794                                  (byte*)&nvi_item.stack.num_digits,\r
1795 #endif\r
1796                                  sizeof(nvi_item.stack),\r
1797                                  item_context);\r
1798 } /* nvio_write_stdial */\r
1799 \r
1800 \f\r
1801 /*===========================================================================\r
1802 \r
1803 FUNCTION NVIO_WRITE_SMS\r
1804 \r
1805 DESCRIPTION\r
1806   This function writes to an sms EFS file.\r
1807 \r
1808 DEPENDENCIES\r
1809   None.\r
1810 \r
1811 RETURN VALUE\r
1812   NV_DONE_S    if it worked\r
1813   NV_BADPARM_S if requested bytes are out of range for NVM\r
1814 \r
1815 SIDE EFFECTS\r
1816   None\r
1817 \r
1818 ===========================================================================*/\r
1819 \r
1820 LOCAL nv_stat_enum_type \r
1821 nvio_write_sms (\r
1822   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
1823 )\r
1824 {\r
1825   int                 return_size;\r
1826   char                sms_name[28]; /* Increasing size from 20 to 28 for context*/\r
1827   nv_stat_enum_type   status = NV_DONE_S;\r
1828 \r
1829   /* only sms supported at this time */\r
1830   if(((cmd_ext_ptr->nvcmd->item != NV_SMS_I) && (cmd_ext_ptr->nvcmd->item != NV_SMS_DM_I)) ||\r
1831      (cmd_ext_ptr->nvcmd->data_ptr->sms.address >= NVI_MAX_SMS_ADDR) ||\r
1832      (cmd_ext_ptr->nvcmd->data_ptr->sms.length > NV_SMS_DATA_SIZ)) {\r
1833     status = NV_BADPARM_S;\r
1834   }\r
1835   else {\r
1836     /* Reset the watchdog timer */\r
1837     KICK_WATCHDOG();\r
1838 \r
1839     if (cmd_ext_ptr->context == 0) /* No context defined */\r
1840     (void)snprintf(sms_name, sizeof(sms_name), "/nvm/sms_%05d",\r
1841                                            cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
1842     else /* Context defined */\r
1843       (void)snprintf(sms_name, sizeof(sms_name), "/nvm/context%d/sms_%05d",\r
1844                      cmd_ext_ptr->context,\r
1845                      cmd_ext_ptr->nvcmd->data_ptr->sms.address);\r
1846 \r
1847     /* Unlink the file before writing to it as the size may be different */\r
1848     if (cmd_ext_ptr->nvcmd->cmd == NV_REPLACE_F)\r
1849       (void)efs_unlink(sms_name);\r
1850 \r
1851     return_size = efs_put( sms_name,\r
1852                      (byte*)&(cmd_ext_ptr->nvcmd->data_ptr->sms.address),\r
1853                      (sizeof(nvi_sms_type) + cmd_ext_ptr->nvcmd->data_ptr->sms.length),\r
1854                       O_CREAT, 0777);\r
1855 \r
1856     if(return_size == -1) {\r
1857       QSR_MSG_HIGH( 2025558454ULL, "Write failed for SMS item address %d",\r
1858                   cmd_ext_ptr->nvcmd->data_ptr->sms.address, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1859       status = NV_FAIL_S;\r
1860     }\r
1861   }\r
1862   return status;\r
1863 } /* nvio_write_sms */\r
1864 \r
1865 \f\r
1866 #ifdef FEATURE_GWSMS\r
1867 /*===========================================================================\r
1868 \r
1869 FUNCTION NVIO_WRITE_SMS_GW\r
1870 \r
1871 DESCRIPTION\r
1872   This function writes to an sms_gw EFS file.\r
1873 \r
1874 DEPENDENCIES\r
1875   None.\r
1876 \r
1877 RETURN VALUE\r
1878   NV_DONE_S    if it worked\r
1879   NV_BADPARM_S if requested bytes are out of range for NVM\r
1880 \r
1881 SIDE EFFECTS\r
1882   None\r
1883 \r
1884 ===========================================================================*/\r
1885 \r
1886 LOCAL nv_stat_enum_type \r
1887 nvio_write_sms_gw (\r
1888   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
1889 )\r
1890 {\r
1891   int return_size;\r
1892   char sms_name[28];    /* Increasing size from 20 to 28*/\r
1893   nv_stat_enum_type   status = NV_DONE_S;\r
1894 \r
1895   /* only sms supported at this time */\r
1896   if ((cmd_ext_ptr->nvcmd->item != NV_SMS_GW_I) ||\r
1897       (cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address >= NVI_MAX_SMS_ADDR) ||\r
1898       (cmd_ext_ptr->nvcmd->data_ptr->sms_gw.length > NV_SMS_GW_DATA_SIZ)) {\r
1899     status =  NV_BADPARM_S;\r
1900   }\r
1901   else {\r
1902     /* Reset the watchdog timer */\r
1903     KICK_WATCHDOG();\r
1904 \r
1905     /* Get the pathname */\r
1906     if (cmd_ext_ptr->context == 0) /* No context is defined */\r
1907     (void) snprintf(sms_name, sizeof(sms_name), "/nvm/sms_gw_%05d",\r
1908                                               cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
1909     else\r
1910       (void) snprintf(sms_name, sizeof(sms_name), "/nvm/context%d/sms_gw_%05d",\r
1911                       cmd_ext_ptr->context,\r
1912                       cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address);\r
1913 \r
1914     /* Unlink the file before writing to it as the size may be different */\r
1915     if (cmd_ext_ptr->nvcmd->cmd == NV_REPLACE_F)\r
1916       (void)efs_unlink(sms_name);\r
1917 \r
1918     return_size = efs_put( sms_name,\r
1919                   (byte*)&(cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address),\r
1920                   (sizeof(nvi_sms_gw_type) + cmd_ext_ptr->nvcmd->data_ptr->sms_gw.length),\r
1921                   O_CREAT, 0777);\r
1922 \r
1923     if(return_size == -1) {\r
1924       QSR_MSG_HIGH( 2025558454ULL, "Write failed for SMS item address %d",\r
1925                 cmd_ext_ptr->nvcmd->data_ptr->sms_gw.address, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
1926       status = NV_FAIL_S;\r
1927     }\r
1928   }\r
1929   return status;\r
1930 } /* nvio_write_sms_gw */\r
1931 #endif\r
1932 \r
1933 \f\r
1934 /*===========================================================================\r
1935 \r
1936 FUNCTION NVIO_WRITE_DIR_NUMBER\r
1937 \r
1938 DESCRIPTION\r
1939   This function performs the "cross-update" between NV_DIR_NUMBER_I and\r
1940   NV_DIR_NUMBER_PCS_I.  That is, a write to either item is translated\r
1941   and copied to the other item as well.  THIS IS A TEMPORARY FUNCTION\r
1942   ONLY USED TO EASE THE TRANSITION FROM THE OLD STRUCTURE TO THE NEW.\r
1943 \r
1944 DEPENDENCIES\r
1945   None.\r
1946 \r
1947 RETURN VALUE\r
1948   NV_DONE_S    if it worked\r
1949   other        if a called function returns a failure status\r
1950 \r
1951 SIDE EFFECTS\r
1952   None\r
1953 \r
1954 ===========================================================================*/\r
1955 \r
1956 LOCAL nv_stat_enum_type \r
1957 nvio_write_dir_number (\r
1958   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
1959 )\r
1960 {\r
1961   nv_stat_enum_type    status;     /* Status to return to calling procedure */\r
1962   nv_cmd_type          local_cmd;\r
1963   static nv_item_type  local_item;\r
1964   byte                 i, index;\r
1965   byte                 pcs_index, gem_index;\r
1966   \r
1967 \r
1968   /* First, update the specified nv item */\r
1969   index = *((byte *)cmd_ext_ptr->nvcmd->data_ptr);\r
1970 \r
1971   if (index >= NV_MAX_NAMS)\r
1972   {\r
1973     status = NV_BADPARM_S;\r
1974   }\r
1975   else\r
1976   {\r
1977     status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
1978                             index,\r
1979                             ((byte *)cmd_ext_ptr->nvcmd->data_ptr) + sizeof(index),\r
1980                             nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
1981                             cmd_ext_ptr->context);\r
1982   }\r
1983 \r
1984   if (status != NV_DONE_S) return status;\r
1985 \r
1986   /* Set up generic command buffer parameters */\r
1987   local_cmd.cmd         = NV_WRITE_F;\r
1988   local_cmd.tcb_ptr     = NULL;\r
1989   local_cmd.sigs        = 0;\r
1990   local_cmd.done_q_ptr  = NULL;\r
1991   local_cmd.data_ptr    = &local_item;\r
1992   local_cmd.status      = NV_DONE_S;\r
1993 \r
1994   /* Now do the cross update */\r
1995   if (cmd_ext_ptr->nvcmd->item == NV_DIR_NUMBER_I) {\r
1996     local_cmd.item = NV_DIR_NUMBER_PCS_I;\r
1997     local_item.mob_dir_number.nam = cmd_ext_ptr->nvcmd->data_ptr->dir_number.nam;\r
1998     for (i=0; i<NV_DIR_NUMB_SIZ; ++i) {\r
1999       local_item.mob_dir_number.digitn[i] = \r
2000          nvt_translate_to_internal\r
2001             (cmd_ext_ptr->nvcmd->data_ptr->dir_number.dir_number[i]);\r
2002     }      \r
2003     local_item.mob_dir_number.n_digits = NV_DIR_NUMB_SIZ;\r
2004   }\r
2005   else {\r
2006     if (cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.n_digits > 15) {\r
2007       return NV_BADPARM_S;\r
2008     }\r
2009     local_cmd.item = NV_DIR_NUMBER_I;\r
2010     local_item.dir_number.nam = cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.nam;\r
2011     for (i=0; i<NV_DIR_NUMB_SIZ; ++i) {\r
2012       local_item.dir_number.dir_number[i] = 0x20;  /* ASCII blank */\r
2013     }\r
2014 \r
2015     /* If n_digits is nonzero, translate and copy the digits; otherwise */\r
2016     /* we've already blanked out all the digits                         */\r
2017     if (cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.n_digits != 0) {\r
2018       pcs_index = MAX(0,(cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.n_digits-10));\r
2019       gem_index = MAX(0, (10-cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.n_digits));\r
2020       while ((gem_index < NV_DIR_NUMB_SIZ)&&(pcs_index < NV_DIR_NUMB_PCS_SIZ)) {\r
2021         local_item.dir_number.dir_number[gem_index++] = \r
2022            nvt_translate_to_external\r
2023               (cmd_ext_ptr->nvcmd->data_ptr->mob_dir_number.digitn[pcs_index++]);\r
2024       }\r
2025     }\r
2026   }     \r
2027 \r
2028    /* Finally, update the "other" nv item */\r
2029    index = *(byte *)(local_cmd.data_ptr);\r
2030    if (index >= NV_MAX_NAMS)\r
2031    {\r
2032      status = NV_BADPARM_S;\r
2033    }\r
2034    else\r
2035    {\r
2036      status = nvio_write_item(local_cmd.item,\r
2037                              index,\r
2038                              ((byte *)(local_cmd.data_ptr) + sizeof(index)),\r
2039                              nvim_op_get_size(local_cmd.item),\r
2040                              cmd_ext_ptr->context);\r
2041  }\r
2042 \r
2043   return status;\r
2044 \r
2045 } /* nvio_write_dir_number */\r
2046 \r
2047 \f\r
2048 /*===========================================================================\r
2049 \r
2050 FUNCTION NVIO_WRITE_RENTAL_TIMER\r
2051 \r
2052 DESCRIPTION\r
2053   This function writes an arbitrary value to the rental timer item.  \r
2054   Since this item is expected to be updated with very high frequency,\r
2055   it is stored in a way that minimizes EEPROM cell wear.  This unusual\r
2056   storage format calls for a special routine to write and read the\r
2057   value.\r
2058   \r
2059   The NV "increment" command would normally be used to update this item;\r
2060   this routine should only be used to initialize the item to some desired\r
2061   specific value.\r
2062   \r
2063 DEPENDENCIES\r
2064   None.\r
2065 \r
2066 RETURN VALUE\r
2067   NV_DONE_S    if it worked\r
2068   other        if a called function returns a failure status\r
2069 \r
2070 SIDE EFFECTS\r
2071   None\r
2072 \r
2073 ===========================================================================*/\r
2074 #ifdef NV_FEATURE_RENTAL_ITEMS\r
2075 #error code not present\r
2076 #endif\r
2077 \r
2078 \f\r
2079 /*===========================================================================\r
2080 \r
2081 FUNCTION NVIM_INCREMENT\r
2082 \r
2083 DESCRIPTION\r
2084   This function processes NVM item "increment" requests.  Currently, only\r
2085   the rental timer item can use this operation.  This special processing\r
2086   is needed because the rental timer item is an unusually high wear item,\r
2087   expected to be written very frequently.\r
2088 \r
2089 DEPENDENCIES\r
2090   None.\r
2091 \r
2092 RETURN VALUE\r
2093   Status of the increment operation.\r
2094 \r
2095 SIDE EFFECTS\r
2096   None.\r
2097 \r
2098 ===========================================================================*/\r
2099 \r
2100 nv_stat_enum_type \r
2101 nvim_increment (\r
2102   nv_cmd_ext_type  *cmd_ext_ptr          /* Command block */\r
2103 )\r
2104 {\r
2105 \r
2106 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2107   \r
2108 #ifndef NV_FEATURE_RENTAL_ITEMS\r
2109   return NV_BADPARM_S;\r
2110 #else\r
2111 #error code not present\r
2112 #endif\r
2113 } /* nvim_increment */\r
2114 \r
2115 \f\r
2116 /*===========================================================================\r
2117 \r
2118 FUNCTION NVIO_WRITE_RENTAL_CNT\r
2119 \r
2120 DESCRIPTION\r
2121   This function writes a value to the rental count item.  This special\r
2122   function is needed because this item is a fixed-pool double-buffered\r
2123   item.\r
2124   \r
2125 DEPENDENCIES\r
2126   None.\r
2127 \r
2128 RETURN VALUE\r
2129   NV_DONE_S    if it worked\r
2130   other        if a called function returns a failure status\r
2131 \r
2132 SIDE EFFECTS\r
2133   None\r
2134 \r
2135 ===========================================================================*/\r
2136 #ifdef NV_FEATURE_RENTAL_ITEMS\r
2137 #error code not present\r
2138 #endif\r
2139 \r
2140 \r
2141 \f\r
2142 /*===========================================================================\r
2143 \r
2144 FUNCTION NVIO_WRITE_PRL_ITEM\r
2145 \r
2146 DESCRIPTION\r
2147   This function writes a PRL item into NVM directory\r
2148 \r
2149 DEPENDENCIES\r
2150   None.\r
2151 \r
2152 RETURN VALUE\r
2153   NV_DONE_S if it worked\r
2154   NV_FAIL_S if it did not work.\r
2155 \r
2156 SIDE EFFECTS\r
2157 \r
2158 ===========================================================================*/\r
2159 nv_stat_enum_type \r
2160 nvio_write_prl_item (\r
2161   int num,\r
2162   void * data_ptr,\r
2163   int item_size\r
2164 )\r
2165 {\r
2166   nv_stat_enum_type  status;      /* Function return value */  \r
2167   int                fd;\r
2168   char               f_name[120];\r
2169   fs_ssize_t         result = 0;\r
2170   fs_size_t          nbytes;\r
2171   fs_size_t          bytes_written;\r
2172   char               *write_buf;\r
2173 \r
2174 \r
2175   QSR_MSG_MED( 2779538831ULL, "size: %d", item_size, 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2176 \r
2177   snprintf(f_name,sizeof(f_name),"/nvm/prl_%d",num);\r
2178 \r
2179   fd = efs_open(f_name, O_RDWR | O_CREAT, 0777 );\r
2180 \r
2181   nbytes = item_size;\r
2182   bytes_written = 0;\r
2183   write_buf = data_ptr;\r
2184 \r
2185   while (bytes_written < nbytes) {\r
2186     result = efs_write (fd,\r
2187     (const void *) (write_buf + bytes_written),\r
2188     nbytes - bytes_written);\r
2189     if (result <= 0)\r
2190       break;\r
2191     bytes_written += (fs_size_t) result;\r
2192   }\r
2193 \r
2194   if (result == -1) {\r
2195     status = NV_FAIL_S;\r
2196   }\r
2197   else\r
2198     status = NV_DONE_S;\r
2199 \r
2200   efs_close(fd);\r
2201 \r
2202   return status;\r
2203 }\r
2204 \r
2205 \f\r
2206 #if (defined(FEATURE_BT) || defined(FEATURE_BT_QSOC))\r
2207 /*===========================================================================\r
2208 \r
2209 FUNCTION NVIO_WRITE_BD_ADDR\r
2210 \r
2211 DESCRIPTION\r
2212   This function processed a write command to the NV_BD_ADDR_I item.\r
2213 \r
2214 DEPENDENCIES\r
2215   None.\r
2216 \r
2217 RETURN VALUE\r
2218   NV_DONE_S if it worked error status code if it failed. \r
2219 \r
2220 SIDE EFFECTS\r
2221   None\r
2222 \r
2223 ===========================================================================*/\r
2224 \r
2225 LOCAL nv_stat_enum_type \r
2226 nvio_write_bd_addr (\r
2227   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
2228 )\r
2229 {\r
2230   int i;\r
2231   nv_stat_enum_type status;\r
2232   nv_bd_addr_type local_bd_addr;  /* tmp buffer for bd_addr */\r
2233   boolean all_zero_write_value;\r
2234   boolean bd_addr_empty = TRUE;\r
2235         \r
2236   /* Read the current Bluetooth addr. value */\r
2237   status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
2238                          0,\r
2239                          (byte*)&local_bd_addr, /* data ptr */\r
2240                           nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2241                           cmd_ext_ptr->context);\r
2242 \r
2243   if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))\r
2244   {\r
2245     return status;\r
2246   }\r
2247 \r
2248 #if 0\r
2249   /* Bluetooth addr can only be written once */\r
2250   if (status == NV_DONE_S) {\r
2251     for (i=0; i<NV_BD_ADDR_SIZE; i++) {\r
2252       if (local_bd_addr.bd_addr[i] != 0) {\r
2253         bd_addr_empty = FALSE;  \r
2254       }\r
2255     }\r
2256     if (!bd_addr_empty)\r
2257     {\r
2258       /* The file is now considered read-only */\r
2259       return NV_READONLY_S;\r
2260     } else {\r
2261 \r
2262       /* The PST may try to write a value of 0 one or more times,\r
2263        simply return success if the current BD_ADDR value is 0 */\r
2264       all_zero_write_value = TRUE;\r
2265       for (i=0; i<NV_BD_ADDR_SIZE; i++) {\r
2266         if (cmd_ext_ptr->nvcmd->data_ptr->bd_addr.bd_addr[i] != 0) {\r
2267           all_zero_write_value = FALSE;\r
2268         }\r
2269       }\r
2270 \r
2271       if (all_zero_write_value) \r
2272       {\r
2273         return NV_DONE_S;\r
2274       }\r
2275     }\r
2276   }\r
2277    #endif      \r
2278   status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2279                           0,\r
2280                            (byte*)cmd_ext_ptr->nvcmd->data_ptr,\r
2281                            nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2282                            cmd_ext_ptr->context);\r
2283      \r
2284   return status;\r
2285 }\r
2286 #endif\r
2287 \r
2288 #ifdef FEATURE_RFCAL_VERSION\r
2289 /*===========================================================================\r
2290 \r
2291 FUNCTION NVIO_WRITE_RF_CAL_DATE\r
2292 \r
2293 DESCRIPTION\r
2294   This function processed a write command to the NV_RF_CAL_DATE_I item.\r
2295 \r
2296 DEPENDENCIES\r
2297   None.\r
2298 \r
2299 RETURN VALUE\r
2300   NV_DONE_S if it worked error status code if it failed. \r
2301 \r
2302 SIDE EFFECTS\r
2303   None\r
2304 \r
2305 ===========================================================================*/\r
2306 \r
2307 LOCAL nv_stat_enum_type \r
2308 nvio_write_rf_cal_date (\r
2309   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
2310 )\r
2311 {\r
2312   nv_stat_enum_type status;\r
2313   dword local_rf_cal_date;  /* tmp buffer for rf_cal_date */\r
2314         \r
2315   /* Read the current rf_cal_date */\r
2316   status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
2317                          0,\r
2318                          &local_rf_cal_date, /* data ptr */\r
2319                           nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2320                           cmd_ext_ptr->context);\r
2321 \r
2322   if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))\r
2323   {\r
2324     return status;\r
2325   }\r
2326         \r
2327   /* rf_cal_date can only be written once */\r
2328   if (status == NV_DONE_S) {\r
2329     if (local_rf_cal_date != 0) {\r
2330       /* The file is now considered read-only */\r
2331       return NV_READONLY_S;\r
2332     }\r
2333     else {\r
2334       /* The PST may try to write a value of 0 one or more times,\r
2335        simply return success if the current rf_cal_date value is 0 */\r
2336       if (cmd_ext_ptr->nvcmd->data_ptr->rf_cal_date == 0) {\r
2337         return NV_DONE_S;\r
2338       }\r
2339     }\r
2340   }\r
2341          \r
2342   status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2343                           0,\r
2344                            (byte*)cmd_ext_ptr->nvcmd->data_ptr,\r
2345                            nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2346                            cmd_ext_ptr->context);\r
2347      \r
2348   return status;\r
2349 }\r
2350 #endif\r
2351 \r
2352 #ifdef FEATURE_RFCAL_VERSION\r
2353 /*===========================================================================\r
2354 \r
2355 FUNCTION NVIO_WRITE_RF_CAL_DAT_FILE\r
2356 \r
2357 DESCRIPTION\r
2358   This function processed a write command to the NV_RF_CAL_DAT_FILE_I item.\r
2359 \r
2360 DEPENDENCIES\r
2361   None.\r
2362 \r
2363 RETURN VALUE\r
2364   NV_DONE_S if it worked error status code if it failed. \r
2365 \r
2366 SIDE EFFECTS\r
2367   None\r
2368 \r
2369 ===========================================================================*/\r
2370 \r
2371 LOCAL nv_stat_enum_type \r
2372 nvio_write_rf_cal_dat_file (\r
2373   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
2374 )\r
2375 {\r
2376   int i;\r
2377   nv_stat_enum_type status;\r
2378   byte local_rf_cal_dat_file[NV_QC_SERIAL_NUM_LEN];  /* tmp buffer for rf_cal_dat_file */\r
2379   boolean all_zero_write_value;\r
2380   boolean empty_value = TRUE;\r
2381         \r
2382   /* Read the current rf_cal_dat_file. value */\r
2383   status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
2384                          0,\r
2385                          &local_rf_cal_dat_file, /* data ptr */\r
2386                           nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2387                           cmd_ext_ptr->context);\r
2388 \r
2389   if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))\r
2390   {\r
2391     return status;\r
2392   }\r
2393         \r
2394   /* rf_cal_dat_file can only be written once */\r
2395   if (status == NV_DONE_S) {\r
2396     for (i=0; i<NV_QC_SERIAL_NUM_LEN; i++) {\r
2397       if (local_rf_cal_dat_file[i] != 0) {\r
2398         empty_value = FALSE;  \r
2399       }\r
2400     }\r
2401     if (!empty_value)\r
2402     {\r
2403       /* The file is now considered read-only */\r
2404       return NV_READONLY_S;\r
2405     } else {\r
2406 \r
2407       /* The PST may try to write a value of 0 one or more times,\r
2408        simply return success if the current rf_cal_dat_file value is 0 */\r
2409       all_zero_write_value = TRUE;\r
2410       for (i=0; i<NV_QC_SERIAL_NUM_LEN; i++) {\r
2411         if (cmd_ext_ptr->nvcmd->data_ptr->rf_cal_dat_file[i] != 0) {\r
2412           all_zero_write_value = FALSE;\r
2413         }\r
2414       }\r
2415 \r
2416       if (all_zero_write_value) \r
2417       {\r
2418         return NV_DONE_S;\r
2419       }\r
2420     }\r
2421   }\r
2422    \r
2423   status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2424                           0,\r
2425                            (byte*)cmd_ext_ptr->nvcmd->data_ptr,\r
2426                            nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2427                            cmd_ext_ptr->context);\r
2428 \r
2429   return status;\r
2430 } /* nvio_write_rf_cal_dat_file */\r
2431 \r
2432 #endif\r
2433 \r
2434 /*===========================================================================\r
2435  \r
2436 FUNCTION NVIO_WRITE_MEID\r
2437  \r
2438 DESCRIPTION\r
2439   This function processed a write command to the NV_MEID_I item.\r
2440  \r
2441 DEPENDENCIES\r
2442   None.\r
2443  \r
2444 RETURN VALUE\r
2445   NV_DONE_S if it worked error status code if it failed. \r
2446  \r
2447 SIDE EFFECTS\r
2448   None\r
2449  \r
2450 ===========================================================================*/\r
2451  \r
2452 LOCAL nv_stat_enum_type \r
2453 nvio_write_meid (\r
2454   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
2455 )\r
2456 {\r
2457   nv_stat_enum_type status;\r
2458   qword local_meid;             /* temporary buffer for meid */\r
2459   local_meid[0] = 0;\r
2460   local_meid[1] = 0;\r
2461 \r
2462   /* Read the current MEID value */\r
2463   status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
2464                           0,\r
2465                           &local_meid, /* data ptr */\r
2466                           nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2467                           cmd_ext_ptr->context);\r
2468 \r
2469   if((status != NV_DONE_S)&&(status != NV_NOTACTIVE_S)) {\r
2470     QSR_MSG_HIGH ( 302884211ULL, " MEID Read was successful. ",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
2471     return status;\r
2472   }\r
2473 \r
2474   if (!(((local_meid[0] == 0) && (local_meid[1] == 0)) ||\r
2475          ((local_meid[0] == 0xFFFFFFFF) \r
2476           && (local_meid[1] == 0x00FFFFFF)))) {\r
2477     /* The file is now considered read-only */\r
2478     QSR_MSG_HIGH ( 911419585ULL, " MEID is neither all 0s nor all Fs. ",0,0,0);//auto-gen, to change remove 'QSR_' and first param\r
2479     return NV_READONLY_S;\r
2480   }\r
2481   status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2482                            0,\r
2483                            (byte*)cmd_ext_ptr->nvcmd->data_ptr,\r
2484                            nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2485                            cmd_ext_ptr->context);\r
2486 \r
2487   return status;\r
2488 } /* nvio_write_meid */\r
2489 \r
2490 \f    \r
2491 /*===========================================================================\r
2492 \r
2493 FUNCTION NVIO_WRITE_IMEI\r
2494 \r
2495 DESCRIPTION\r
2496   This function processed a write command to the NV_UE_IMEI_I item.\r
2497 \r
2498 DEPENDENCIES\r
2499   None.\r
2500 \r
2501 RETURN VALUE\r
2502   NV_DONE_S if it worked error status code if it failed. \r
2503 \r
2504 SIDE EFFECTS\r
2505   None\r
2506 \r
2507 ===========================================================================*/\r
2508 \r
2509 LOCAL nv_stat_enum_type \r
2510 nvio_write_imei\r
2511 (\r
2512   nv_cmd_ext_type         *cmd_ext_ptr       /* Command block */\r
2513 )\r
2514 {\r
2515     int i;\r
2516   nv_stat_enum_type status = NV_FAIL_S;\r
2517     nv_ue_imei_type local_ue_imei;  /* tmp buffer for ue_imei */\r
2518     boolean all_zero_write_value;\r
2519     boolean ue_imei_empty = TRUE;\r
2520 #ifdef FEATURE_NV_SFS_PRIVATE\r
2521   sfs_priv_errno_enum_type sfs_ret = 0;\r
2522 #endif\r
2523     \r
2524 #if defined (FEATURE_NV_SFS_PRIVATE)\r
2525   /* If IMEI can't be read, call it "not active" */\r
2526   sfs_ret = sfs_priv_imei_read((uint8 *) &local_ue_imei, \r
2527                         nvim_op_get_size(cmd_ext_ptr->nvcmd->item));\r
2528   if ( sfs_ret == SFS_PRIV_INACTIVE )\r
2529   {\r
2530     status = NV_NOTACTIVE_S;\r
2531   } \r
2532   else if( sfs_ret == SFS_PRIV_SUCCESS)\r
2533   {\r
2534     status = NV_DONE_S;\r
2535   }\r
2536   else\r
2537   {\r
2538     status = NV_FAIL_S;\r
2539   }\r
2540 #else\r
2541     /* Read the current IMEI value */\r
2542     status = nvio_read_item(cmd_ext_ptr->nvcmd->item,\r
2543                             0,\r
2544                             (byte*)&local_ue_imei, /* data ptr */\r
2545                              nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2546                             cmd_ext_ptr->context);\r
2547 #endif\r
2548 \r
2549     if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))\r
2550     {\r
2551       return status;\r
2552     }\r
2553 \r
2554   /* IMEI has been written once */\r
2555   if (status == NV_DONE_S) \r
2556   {\r
2557     for (i=0; i<NV_UE_IMEI_SIZE; i++) \r
2558     {\r
2559       if (local_ue_imei.ue_imei[i] != 0) \r
2560       {\r
2561           ue_imei_empty = FALSE;  \r
2562         }\r
2563       }\r
2564       if (!ue_imei_empty)\r
2565       {\r
2566         /* The file is now considered read-only */\r
2567       status = NV_READONLY_S;\r
2568     } \r
2569     else \r
2570     {\r
2571         /* The PST may try to write a value of 0 one or more times,\r
2572          simply return success if the current IMEI value is 0 */\r
2573         all_zero_write_value = TRUE;\r
2574       for (i=0; i<NV_UE_IMEI_SIZE; i++) \r
2575       {\r
2576         if (cmd_ext_ptr->nvcmd->data_ptr->ue_imei.ue_imei[i] != 0)\r
2577         {\r
2578             all_zero_write_value = FALSE;\r
2579           }\r
2580         }\r
2581 \r
2582         if (all_zero_write_value) \r
2583         {\r
2584         status = NV_DONE_S;\r
2585       }\r
2586     }\r
2587   } /* IMEI has been written once */\r
2588 \r
2589 #ifdef FEATURE_NV_SFS_PRIVATE\r
2590   sfs_ret = sfs_priv_imei_write((uint8 *)cmd_ext_ptr->nvcmd->data_ptr,\r
2591                                 nvim_op_get_size(cmd_ext_ptr->nvcmd->item));\r
2592   /* If IMEI can't be written, call it "read-only" */\r
2593   if ( sfs_ret == SFS_PRIV_READONLY ) \r
2594   {\r
2595     /* SFS sees that Qfuse is blown so readonly */\r
2596     status = NV_READONLY_S;      \r
2597   } \r
2598   else if( sfs_ret == SFS_PRIV_SUCCESS)\r
2599   {\r
2600     /* SFS write succeeded */\r
2601     status = NV_DONE_S;\r
2602   }\r
2603   else\r
2604   {\r
2605     /* There is a failure to write at the SFS layer*/\r
2606     status = NV_FAIL_S;\r
2607   }\r
2608 #else\r
2609   /* IMEI has not been written yet */\r
2610   else \r
2611   {\r
2612     status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2613                              0,\r
2614                              (byte*)cmd_ext_ptr->nvcmd->data_ptr,\r
2615                              nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2616                              cmd_ext_ptr->context);\r
2617   } /* IMEI has not been written yet */\r
2618 #endif\r
2619 \r
2620     return status;\r
2621 } /* nvio_write_imei */\r
2622 \r
2623 \f\r
2624 /*===========================================================================\r
2625 \r
2626 FUNCTION NVIO_WRITE\r
2627 \r
2628 DESCRIPTION\r
2629   This function processes NVM write requests.  The function checks\r
2630   to make sure that a valid item has been requested, it performs any\r
2631   translations necessary from external format to internal NVM format\r
2632   and writes the item using EFS write services.\r
2633 \r
2634 DEPENDENCIES\r
2635   None.\r
2636 \r
2637 RETURN VALUE\r
2638   Status of write operation.\r
2639 \r
2640 SIDE EFFECTS\r
2641   None.\r
2642 \r
2643 ===========================================================================*/\r
2644 \r
2645 nv_stat_enum_type \r
2646 nvio_write (\r
2647   nv_cmd_ext_type  *cmd_ext_ptr          /* Command block */\r
2648 )\r
2649 {\r
2650   nv_stat_enum_type status;     /* Status to return to calling procedure */\r
2651   uint16 array_size; /* Array size of the item */\r
2652   byte   index; /* Specific index of an array */\r
2653 \r
2654 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2655   \r
2656   /* Check that the item code is within range. If it is not */\r
2657   /* then exit with fail status, else switch on item type.  */\r
2658 \r
2659   if (cmd_ext_ptr->nvcmd->item >= NV_MAX_I) {\r
2660     return NV_BADPARM_S;\r
2661   }\r
2662   else \r
2663   {\r
2664 \r
2665 #ifdef NV_FEATURE_DIAG_WINS\r
2666     /* If write request is from diag, close gate to all other writers */\r
2667     if ((write_gate_open) || (cmd_ext_ptr->nvcmd->tcb_ptr == &diag_tcb))\r
2668     {\r
2669       if (cmd_ext_ptr->nvcmd->tcb_ptr == &diag_tcb)\r
2670       {\r
2671          write_gate_open = FALSE;\r
2672       }\r
2673 #endif      \r
2674 \r
2675 #ifdef FEATURE_NV_RUIM\r
2676 \r
2677       /* If the R-UIM supports the item,\r
2678        * return the status else use "regular" NVM.\r
2679        */\r
2680       if (cmd_ext_ptr->context == 0) {\r
2681         if ( nvruim_write(cmd_ext_ptr->nvcmd, &status) == NV_RUIM_SUPPORTS_ITEM ) {\r
2682         return status;\r
2683         }\r
2684       }\r
2685 #ifdef FEATURE_DUAL_STANDBY\r
2686       else {\r
2687         if ( nvruim_write_ext(cmd_ext_ptr, &status) == NV_RUIM_SUPPORTS_ITEM ) {\r
2688         return status;\r
2689         }\r
2690       }\r
2691 #endif\r
2692 #endif\r
2693 \r
2694       switch (cmd_ext_ptr->nvcmd->item)\r
2695       {\r
2696 \r
2697       /* For each requested parameter if the parameter is fixed then */\r
2698       /* write it via its pointer from the external requestor's data */\r
2699       /* buffer to an EFS file. Any required                         */\r
2700       /* translation from external to internal format is performed   */\r
2701       /* as part of this write.                                      */\r
2702 \r
2703 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2704 \r
2705       case NV_ESN_I:\r
2706         status = nvio_write_esn(cmd_ext_ptr);\r
2707         break;\r
2708 \r
2709 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2710 \r
2711       case NV_ESN_ME_I:\r
2712         status = NV_READONLY_S;      \r
2713         break;\r
2714 \r
2715 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2716 \r
2717       case NV_ESN_CHKSUM_I:\r
2718      \r
2719         /* The ESN checksum cannot be written from external   */\r
2720         /* request.  This request is denied and the NV task   */\r
2721         /* initiates transition of the DMSS to offline state  */\r
2722         /* (not yet implemented).                             */\r
2723         status = NV_READONLY_S;      \r
2724         break;\r
2725 \r
2726 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2727 \r
2728       case NV_VERNO_MAJ_I:\r
2729 \r
2730         /* Major version can be written only internally, directly */\r
2731         /* from nv_init.  So we do not allow writing it here.     */\r
2732 \r
2733         status = NV_READONLY_S;      \r
2734         break;\r
2735 \r
2736 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2737 \r
2738       case NV_VERNO_MIN_I:\r
2739 \r
2740         /* Minor version can be written only internally, directly */\r
2741         /* from nv_init.  So we do not allow writing it here.     */\r
2742 \r
2743         status = NV_READONLY_S;      \r
2744         break;\r
2745                      \r
2746 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2747 \r
2748       case NV_DIAL_I:\r
2749           status = nvio_write_dial(NV_DIAL_I,\r
2750                                  NV_MAX_SPEED_DIALS,\r
2751                                  cmd_ext_ptr->nvcmd->data_ptr->dial.address,\r
2752                                  &cmd_ext_ptr->nvcmd->data_ptr->dial,\r
2753                                  cmd_ext_ptr->context);\r
2754         break;\r
2755  \r
2756 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2757 \r
2758       case NV_STACK_I:\r
2759           status = nvio_write_stdial(NV_STACK_I,\r
2760                                  NV_MAX_STACK_DIALS,\r
2761                                  cmd_ext_ptr->nvcmd->data_ptr->stack.address,\r
2762                                  &cmd_ext_ptr->nvcmd->data_ptr->stack,\r
2763                                  cmd_ext_ptr->context);\r
2764         break;\r
2765 \r
2766 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2767 \r
2768 #ifdef FEATURE_NV_REDIAL_ITEM\r
2769       case NV_REDIAL_I:\r
2770         status = nvio_write_dial(NV_DIAL_I,\r
2771                                  NV_MAX_SPEED_DIALS + NVI_REDIAL_EXTENSIONS,\r
2772                                  NV_MAX_SPEED_DIALS,\r
2773                                  &cmd_ext_ptr->nvcmd->data_ptr->dial,\r
2774                                  cmd_ext_ptr->context);\r
2775         break;\r
2776 #endif\r
2777 \r
2778 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2779 \r
2780       case NV_SMS_I:\r
2781       case NV_SMS_DM_I:\r
2782         status = nvio_write_sms(cmd_ext_ptr);\r
2783         break;\r
2784 \r
2785 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2786 \r
2787       case NV_DIR_NUMBER_I:\r
2788       case NV_DIR_NUMBER_PCS_I :\r
2789         status = nvio_write_dir_number(cmd_ext_ptr);\r
2790         break;\r
2791 \r
2792 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2793 \r
2794 #ifdef NV_FEATURE_RENTAL_ITEMS\r
2795 #error code not present\r
2796 #endif\r
2797 \r
2798 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2799 \r
2800 #ifdef NV_FEATURE_RENTAL_ITEMS\r
2801 #error code not present\r
2802 #endif\r
2803 \r
2804 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2805       case NV_A_KEY_I:\r
2806       case NV_SSD_A_I:\r
2807       case NV_SSD_B_I:\r
2808         \r
2809         /* Write the item */\r
2810         index = *((byte *)cmd_ext_ptr->nvcmd->data_ptr);\r
2811         if (index >= NV_MAX_NAMS) {\r
2812           status = NV_BADPARM_S;\r
2813         }\r
2814         else   /* Valid index */ {\r
2815           status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2816                                    index,\r
2817                                  ((byte *)cmd_ext_ptr->nvcmd->data_ptr) + sizeof(index),\r
2818                                    nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2819                                    cmd_ext_ptr->context);\r
2820         }\r
2821         \r
2822       break;\r
2823 \r
2824 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2825 \r
2826       case NV_PAP_PASSWORD_I:\r
2827         #ifdef NV_FEATURE_PAP\r
2828            status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2829                                     0,\r
2830                                     (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
2831                                     nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2832                                     cmd_ext_ptr->context);\r
2833         #else\r
2834            status = NV_BADPARM_S;\r
2835         #endif\r
2836         break;\r
2837 \r
2838 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2839 \r
2840       case NV_UP_KEY_I:\r
2841         #ifdef NV_FEATURE_UP\r
2842 \r
2843           index = *((byte *) cmd_ext_ptr->nvcmd->data_ptr);\r
2844           if (index >= NV_UP_LINK_INFO_TABLE_SIZE) {\r
2845             status = NV_BADPARM_S;\r
2846           }\r
2847           else /* Valid index */ {\r
2848             status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2849                                      index,\r
2850                                   ((byte *)cmd_ext_ptr->nvcmd->data_ptr) + sizeof(index),\r
2851                                      nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2852                                      cmd_ext_ptr->context);\r
2853           }\r
2854 \r
2855         #else\r
2856           status = NV_BADPARM_S;\r
2857         #endif\r
2858         break;\r
2859                                   \r
2860 /*- - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2861   \r
2862 /*  Roaming List is handled differently in the item manager (not a generic case) */\r
2863 #ifdef NV_FEATURE_PRL_ITEMS\r
2864 \r
2865   #ifdef NV_FEATURE_IS683A_PRL \r
2866       case NV_ROAMING_LIST_683_I:\r
2867         status = nvio_write_roaming_list(cmd_ext_ptr);\r
2868         break;\r
2869   #else    \r
2870       case NV_ROAMING_LIST_I: \r
2871         status = nvio_write_roaming_list(cmd_ext_ptr);\r
2872         break;\r
2873   #endif\r
2874 #endif\r
2875 \r
2876 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2877 \r
2878       case NV_BD_ADDR_I:\r
2879         #if (defined(FEATURE_BT) || defined(FEATURE_BT_QSOC))\r
2880           status = nvio_write_bd_addr(cmd_ext_ptr);\r
2881         #else\r
2882           status = NV_BADPARM_S;\r
2883         #endif\r
2884         break;\r
2885 \r
2886 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2887 \r
2888       case NV_UE_IMEI_I:\r
2889         status = nvio_write_imei(cmd_ext_ptr);\r
2890         break;\r
2891 \r
2892 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2893 \r
2894 #ifdef FEATURE_GWSMS\r
2895       case NV_SMS_GW_I:\r
2896         status = nvio_write_sms_gw(cmd_ext_ptr);\r
2897         break;\r
2898 #endif\r
2899 \r
2900 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2901 \r
2902       case NV_RF_CAL_DATE_I:\r
2903         #ifdef FEATURE_RFCAL_VERSION\r
2904           status = nvio_write_rf_cal_date(cmd_ext_ptr);\r
2905         #else\r
2906           status = NV_BADPARM_S;\r
2907         #endif\r
2908         break;\r
2909 \r
2910 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2911 \r
2912       case NV_RF_CAL_DAT_FILE_I:\r
2913         #ifdef FEATURE_RFCAL_VERSION\r
2914           status = nvio_write_rf_cal_dat_file(cmd_ext_ptr);\r
2915         #else\r
2916           status = NV_BADPARM_S;\r
2917         #endif\r
2918         break;\r
2919 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2920 \r
2921 #ifdef FEATURE_NV_SUPPORT_FLASH_OTP\r
2922 \r
2923       case NV_DEVICE_SERIAL_NO_I:\r
2924         if (flash_otp_operation(FLASH_OTP_OP_SERIALNO_WRITE,\r
2925                         (byte *)cmd_ext_ptr->nvcmd->data_ptr) != FLASH_OTP_IO_SUCCESS) {\r
2926           return NV_FAIL_S;\r
2927         }\r
2928         else {\r
2929           return NV_DONE_S;\r
2930         }\r
2931 #endif\r
2932 \r
2933 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2934 \r
2935       case NV_MEID_I:\r
2936         status = nvio_write_meid(cmd_ext_ptr);\r
2937         break;\r
2938 \r
2939 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2940 \r
2941       case NV_MEID_ME_I:\r
2942         status = NV_READONLY_S;      \r
2943         break;\r
2944 \r
2945 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2946 \r
2947       case NV_MS_SMS_AUTOSAVE_I:\r
2948         status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2949                                   0,\r
2950                                   (byte *)cmd_ext_ptr->nvcmd->data_ptr,\r
2951                                   nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2952                                   cmd_ext_ptr->context);\r
2953         break;\r
2954 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2955 \r
2956       default:\r
2957         /* All other items get generic treatment, if they have \r
2958             a valid entry */\r
2959         if (nvim_op_get_presence(cmd_ext_ptr->nvcmd->item)) {\r
2960           array_size = nvim_op_get_array_size(cmd_ext_ptr->nvcmd->item);\r
2961 \r
2962           if (array_size == 0) {\r
2963             status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2964                                      0,\r
2965                                      (void *) cmd_ext_ptr->nvcmd->data_ptr,\r
2966                                      nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2967                                      cmd_ext_ptr->context);\r
2968           }\r
2969           else /* More than one item */ {\r
2970             index = *((byte *) cmd_ext_ptr->nvcmd->data_ptr);\r
2971             if (index >= array_size) {\r
2972               status = NV_BADPARM_S;\r
2973             }\r
2974             else {\r
2975               //QSR_MSG_MED( 3068207423ULL, "Data after: %.4x", *(((byte *) cmd_ext_ptr->data_ptr) + sizeof(index)), 0, 0);//auto-gen, to change remove 'QSR_' and first param\r
2976               status = nvio_write_item(cmd_ext_ptr->nvcmd->item,\r
2977                                        index,\r
2978                                        ((byte *)cmd_ext_ptr->nvcmd->data_ptr)+sizeof(index),\r
2979                                        nvim_op_get_size(cmd_ext_ptr->nvcmd->item),\r
2980                                        cmd_ext_ptr->context);\r
2981             }\r
2982           }\r
2983         }\r
2984         else   /* Not a valid entry */ {\r
2985           ERR("nvw_write %d not for this target", cmd_ext_ptr->nvcmd->item, 0, 0);\r
2986           status = NV_BADPARM_S;\r
2987         }\r
2988 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/\r
2989       }/* switch */\r
2990 \r
2991       return status;\r
2992 \r
2993 #ifdef NV_FEATURE_DIAG_WINS\r
2994     }\r
2995     else\r
2996     {\r
2997       /* If write gate is closed, tell callers write succeeded even though */\r
2998       /* it didn't really (avoids recovery processing in client code)      */\r
2999 \r
3000       return NV_DONE_S;\r
3001     }\r
3002 #endif  \r
3003   } /* if */\r
3004 } /* nvio_write */\r
3005                    \r
3006 #endif /* FEATURE_NV_ITEM_MGR */\r