comparison src/aci2/aci/phb.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : MMI-Framework (8417)
4 | Modul : PHB
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul contains the functions to establish the phone books.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef TI_PS_FFS_PHB
22
23 #include "aci_all.h"
24
25 #include "aci_cmh.h"
26 #include "ati_cmd.h"
27 #include "aci_cmd.h"
28 #include "aci.h"
29 #include "p_sim.h"
30 #include "pcm.h"
31 #include "gdi.h"
32
33 #include "phb.h"
34 #include "psa.h"
35 #include "psa_sim.h"
36 #include "psa_cc.h"
37 #ifdef SIM_TOOLKIT
38 #include "psa_sat.h"
39 #endif
40
41 #ifdef FAX_AND_DATA
42 #include "aci_fd.h"
43 #endif /* of #ifdef FAX_AND_DATA */
44
45 #include "cmh.h"
46 #include "cmh_phb.h"
47
48 #include "dti_conn_mng.h"
49
50
51 #include "cmh_sim.h"
52 #include "psa_mm.h"
53 #include "psa_ss.h"
54
55 #ifndef _SIMULATION_
56 #include "ffs\ffs.h"
57 #endif
58 /********* current define *******************************************/
59 static T_PHB_EXT_CMP_FCT ext_compare_fct = NULL; /* external compare function */
60 static T_PHB_CTB phb_ctb[MAX_PHONEBOOK];
61 static T_PHB_AFB_ELEMENT phb_element[MAX_AFB_RECORDS];
62 static T_PHB_RDM_ELEMENT phb_l_element[MAX_RDM_RECORDS];
63 static UBYTE adn_bitmap[MAX_ADN_BITMAP];
64 static UBYTE fdn_bitmap[MAX_FDN_BITMAP];
65 static UBYTE bdn_bitmap[MAX_BDN_BITMAP];
66 static UBYTE sdn_bitmap[MAX_SDN_BITMAP];
67 static UBYTE ecc_bitmap[MAX_ECC_BITMAP];
68 static UBYTE upn_bitmap[MAX_UPN_BITMAP];
69 #ifdef PHONEBOOK_EXTENSION
70 static T_PHB_EXT_RECORDS phb_ext_records[MAX_PHB_EXT];
71 static UBYTE ext1_bitmap[MAX_EXT1_BITMAP];
72 static UBYTE ext2_bitmap[MAX_EXT2_BITMAP];
73 #endif
74 static UBYTE sim_service_table[MAX_SRV_TBL]; /* SIM service table */
75 static UBYTE data [256];
76
77 static SHORT ext_index;
78 static UBYTE max_ext_chain_reads=0;
79 static UBYTE phb_stat;
80 static UBYTE fdn_mode;
81 static T_ACI_CLASS fdn_classtype;
82 static T_ACI_CLASS fdn_input_classtype;
83 static UBYTE read_flag = 0;
84 static SHORT db_index; /* memory index for delete whole phonebook */
85 static BOOL sstUpdateId = FALSE; /* SIM service table update indication (SAT) */
86
87 static UBYTE max_sim_LDN_records = 0; /* to ensure that every physical record is written */
88
89 static int cmpString (UBYTE *s1, UBYTE *s2, UBYTE len);
90 static int pb_cmp_phb_entry ( UBYTE *pb_tag, UBYTE pb_len,
91 T_ACI_PB_TEXT *search_tag );
92 static int pb_cmp2Bytes(UBYTE *s1, UBYTE *s2, UBYTE len, UBYTE flag);
93 static void pb_cvt_alpha_for_cmp ( UBYTE *src,
94 UBYTE *dst,
95 UBYTE len );
96 static BOOL imsiFlag;
97
98 static BOOL pause_pb_reading_while_EXT_reading = FALSE; /* pauses the loop while reading EXT-Records */
99 static SHORT paused_table_id = 0; /* the paused record */
100 EXTERN T_PCEER causeMod;
101 EXTERN SHORT causeCeer;
102
103 #ifdef SIM_TOOLKIT
104 BOOL pb_update (int ref, T_SIM_FILE_UPDATE_IND *fu);
105 BOOL pb_update_ecc_fu (int ref, T_SIM_FILE_UPDATE_IND *fu);
106 #endif
107 void pb_copy_ecc_entry (UBYTE *ecc, UBYTE num);
108 void pb_read_sim_ecc ( void );
109 void pb_read_eeprom_ecc (void);
110 T_PHB_RETURN pb_read_eeprom_req(void);
111 BOOL pb_read_sim_dat(USHORT data_id, UBYTE len, UBYTE max_length);
112 void pb_read_sim_dat_cb(SHORT table_id);
113 void pb_read_sim_req(void);
114 void pb_sat_update_reset (USHORT data_id);
115 void pb_init_afb(void);
116 void pb_init_ctb (T_PHB_TYPE book);
117 void pb_init_element (UBYTE book);
118 void pb_init_l_element (UBYTE book); /*CQ16301: Added support for LND Refresh*/
119
120 BOOL pb_init_sync_sim(UBYTE type);
121 BOOL pb_prepare_sync_sim(UBYTE type, UBYTE rcd_num);
122 BOOL pb_sync_sim(UBYTE type, UBYTE rcd_num);
123 void pb_sync_sim_cb(SHORT table_id);
124 void pb_finish_sync_sim(void);
125
126 void copy_phb_element ( T_PHB_RECORD *entry, T_PHB_AFB_ELEMENT phb_element );
127 void copy_phb_l_element ( T_PHB_RECORD *entry, T_PHB_RDM_ELEMENT phb_l_element );
128
129
130 LOCAL USHORT pb_get_ext_file_id (UBYTE pb_type);
131 LOCAL void pb_prepare_ext_data(UBYTE *number, UBYTE no_len,
132 UBYTE *subaddr, UBYTE sub_len,
133 USHORT file_id);
134 /*
135 +--------------------------------------------------------------------+
136 | PROJECT: MMI-Framework (8417) MODULE: PHB |
137 | STATE : code ROUTINE: pb_sat_update_reset |
138 +--------------------------------------------------------------------+
139
140 PURPOSE : Initialisation of phonebook field for SAT REFRESH
141 */
142
143 void pb_sat_update_reset (USHORT data_id)
144 {
145 TRACE_FUNCTION("pb_sat_update_reset()");
146
147 #ifdef SIM_TOOLKIT
148 switch (data_id)
149 {
150 /* ACI-ENH-17240: Subissue of CQ 16303, ADN and FDN are updated
151 if one of them has changed */
152 case SIM_ADN:
153 /*
154 * pb_init_element (ADN);
155 * pb_init_ctb (ADN);
156 * phb_ctb[ADN].rcd_bitmap = adn_bitmap;
157 * memset(phb_ctb[ADN].rcd_bitmap, 0, MAX_ADN_BITMAP);
158 * break;
159 */
160 case SIM_FDN:
161 /*
162 * pb_init_element (FDN);
163 * pb_init_ctb (FDN);
164 * phb_ctb[FDN].rcd_bitmap = fdn_bitmap;
165 * memset(phb_ctb[FDN].rcd_bitmap, 0, MAX_FDN_BITMAP);
166 */
167 pb_init_afb();
168 break;
169
170 case SIM_BDN:
171 pb_init_element (BDN);
172 pb_init_ctb (BDN);
173 phb_ctb[BDN].rcd_bitmap = bdn_bitmap;
174 memset(phb_ctb[BDN].rcd_bitmap, 0, MAX_BDN_BITMAP);
175 break;
176
177 case SIM_SDN:
178 pb_init_element (SDN);
179 pb_init_ctb (SDN);
180 phb_ctb[SDN].rcd_bitmap = sdn_bitmap;
181 memset(phb_ctb[SDN].rcd_bitmap, 0, MAX_SDN_BITMAP);
182 break;
183
184 case SIM_MSISDN:
185 pb_init_element (UPN);
186 pb_init_ctb (UPN);
187 phb_ctb[UPN].rcd_bitmap = upn_bitmap;
188 memset(phb_ctb[UPN].rcd_bitmap, 0, MAX_UPN_BITMAP);
189 break;
190
191 /* CQ16301: Added support for LND refresh triggered by SAT */
192 case SIM_LND:
193 pb_init_l_element (LDN);
194 pb_init_ctb (LDN);
195 break;
196
197 default:
198 break;
199 }
200 #endif
201 }
202
203 /*
204 +--------------------------------------------------------------------+
205 | PROJECT: MMI-Framework (8417) MODULE: PHB |
206 | STATE : code ROUTINE: pb_init_ctb |
207 +--------------------------------------------------------------------+
208
209 PURPOSE : Initialisation of the phonebook control block,
210 but not for bitmap field
211 */
212
213 void pb_init_ctb (T_PHB_TYPE book)
214 {
215 TRACE_FUNCTION("pb_init_ctb()");
216
217 phb_ctb[book].mem = NO_PHB_ENTRY;
218 phb_ctb[book].alpha_len = 0;
219 phb_ctb[book].max_rcd = 0;
220 phb_ctb[book].used_rcd = 0;
221 phb_ctb[book].first_rcd = UNUSED_INDEX;
222 phb_ctb[book].first_trcd = UNUSED_INDEX;
223 phb_ctb[book].first_nrcd = UNUSED_INDEX;
224 phb_ctb[book].first_mtrcd = UNUSED_INDEX;
225 phb_ctb[book].first_mnrcd = UNUSED_INDEX;
226 }
227
228 /*
229 +--------------------------------------------------------------------+
230 | PROJECT: MMI-Framework (8417) MODULE: PHB |
231 | STATE : code ROUTINE: pb_init_element |
232 +--------------------------------------------------------------------+
233
234 PURPOSE : Initialisation of the saved phonebook element
235 */
236
237 void pb_init_element (UBYTE book)
238 {
239 SHORT index;
240
241 TRACE_FUNCTION("pb_init_element()");
242
243 index = phb_ctb[book].first_rcd;
244 while (index NEQ UNUSED_INDEX)
245 {
246 phb_element[index].free = PHB_ELEMENT_FREE;
247 index = phb_element[index].next_rcd;
248 }
249 }
250
251 /*
252 +--------------------------------------------------------------------+
253 | PROJECT: MMI-Framework (8417) MODULE: PHB |
254 | STATE : code ROUTINE: pb_init_l_element |
255 +--------------------------------------------------------------------+
256
257 PURPOSE : Initialisation of the saved phonebook element (ME)
258 */
259
260 void pb_init_l_element (UBYTE book)
261 {
262 SHORT index;
263
264 TRACE_FUNCTION("pb_init_l_element()");
265
266 index = phb_ctb[book].first_rcd;
267 while (index NEQ UNUSED_INDEX)
268 {
269 phb_l_element[index].free = PHB_ELEMENT_FREE;
270 index = phb_element[index].next_rcd;
271 }
272 }
273
274 /*
275 +--------------------------------------------------------------------+
276 | PROJECT: MMI-Framework (8417) MODULE: PHB |
277 | STATE : code ROUTINE: phb_Init |
278 +--------------------------------------------------------------------+
279
280 PURPOSE : Power-on initialisation of the phonebook module
281 */
282
283 void phb_Init (void)
284 {
285 fdn_mode = NO_OPERATION;
286 /* set fdn_classtype to default value */
287 fdn_classtype = CLASS_VceDatFaxSms;
288 fdn_input_classtype = fdn_classtype;
289 #ifdef SIM_TOOLKIT
290 simShrdPrm.fuRef=-1;
291 if (!psaSAT_FURegister (pb_update))
292 {
293 TRACE_EVENT ("FAILED to register the handler pb_update() for FU");
294 }
295 if (!psaSAT_FURegister (pb_update_ecc_fu))
296 {
297 TRACE_EVENT ("FAILED to register the handler pb_update_ecc_fu() for FU");
298 }
299
300 #endif
301 }
302
303 /*
304 +--------------------------------------------------------------------+
305 | PROJECT: MMI-Framework (8417) MODULE: PHB |
306 | STATE : code ROUTINE: pb_init |
307 +--------------------------------------------------------------------+
308
309 PURPOSE :
310 */
311
312 void pb_init (void)
313 {
314 TRACE_FUNCTION ("pb_init()");
315
316 if (fdn_mode EQ NO_OPERATION)
317 {
318 {
319 T_PHB_TYPE i;
320
321 /* Initiate the bitmap in control block */
322 for (i=0; i<MAX_PHONEBOOK; i++)
323 {
324 pb_init_ctb(i);
325
326 switch(i)
327 {
328 case ECC:
329 phb_ctb[i].rcd_bitmap = ecc_bitmap;
330 memset(phb_ctb[i].rcd_bitmap, 0, MAX_ECC_BITMAP);
331 break;
332 case ADN:
333 phb_ctb[i].rcd_bitmap = adn_bitmap;
334 memset(phb_ctb[i].rcd_bitmap, 0, MAX_ADN_BITMAP);
335 break;
336 case FDN:
337 phb_ctb[i].rcd_bitmap = fdn_bitmap;
338 memset(phb_ctb[i].rcd_bitmap, 0, MAX_FDN_BITMAP);
339 break;
340 case BDN:
341 phb_ctb[i].rcd_bitmap = bdn_bitmap;
342 memset(phb_ctb[i].rcd_bitmap, 0, MAX_BDN_BITMAP);
343 break;
344 case SDN:
345 phb_ctb[i].rcd_bitmap = sdn_bitmap;
346 memset(phb_ctb[i].rcd_bitmap, 0, MAX_SDN_BITMAP);
347 break;
348 case UPN:
349 phb_ctb[i].rcd_bitmap = upn_bitmap;
350 memset(phb_ctb[i].rcd_bitmap, 0, MAX_UPN_BITMAP);
351 break;
352 }
353 }
354 }
355 #ifdef PHONEBOOK_EXTENSION
356 {
357 T_PHB_EXT_TYPE i;
358 /* Initiate the bitmap for the phonebook extention records */
359 for (i = 0; i < MAX_PHB_EXT; i++)
360 {
361 phb_ext_records[i].mem = NO_PHB_ENTRY;
362 phb_ext_records[i].max_rcd = 0;
363 switch (i)
364 {
365 case EXT1:
366 phb_ext_records[i].rcd_bitmap = ext1_bitmap;
367 memset(phb_ext_records[i].rcd_bitmap, 0, MAX_EXT1_BITMAP); /* ADN; LDN */
368 break;
369
370 case EXT2:
371 phb_ext_records[i].rcd_bitmap = ext2_bitmap;
372 memset(phb_ext_records[i].rcd_bitmap, 0, MAX_EXT2_BITMAP); /* FDN */
373 break;
374 }
375 }
376 }
377 #endif
378 {
379 int i;
380 /* Initiate the free element */
381 for (i=0; i<MAX_AFB_RECORDS; i++)
382 phb_element[i].free = PHB_ELEMENT_FREE;
383 for (i=0; i<MAX_RDM_RECORDS; i++)
384 phb_l_element[i].free = PHB_ELEMENT_FREE;
385 }
386
387 phb_stat = PHB_UNKNOWN;
388 cmhPHB_StatIndication ( PHB_UNKNOWN, CME_ERR_NotPresent, TRUE );
389 }
390 }
391
392
393 /*
394 +--------------------------------------------------------------------+
395 | PROJECT: MMI-Framework (8417) MODULE: PHB |
396 | STATE : code ROUTINE: pb_init_afb |
397 +--------------------------------------------------------------------+
398
399
400 PURPOSE :
401
402 */
403
404 void pb_init_afb(void)
405 {
406 T_PHB_TYPE i;
407 SHORT index;
408 SHORT cur_index;
409
410 TRACE_FUNCTION ("pb_init_afb()");
411
412 /* Initiate the bitmap in control block */
413 for (i=0; i<MAX_PHONEBOOK; i++)
414 {
415 switch (i)
416 {
417 case ADN:
418 case FDN:
419 index = phb_ctb[i].first_rcd;
420 while (index != UNUSED_INDEX)
421 {
422 cur_index = index;
423 index = phb_element[cur_index].next_rcd;
424 phb_element[cur_index].free = PHB_ELEMENT_FREE;
425 phb_element[cur_index].prev_rcd = UNUSED_INDEX;
426 phb_element[cur_index].next_rcd = UNUSED_INDEX;
427 }
428 pb_init_ctb(i);
429 switch(i)
430 {
431 case ADN:
432 phb_ctb[i].rcd_bitmap = adn_bitmap;
433 memset(phb_ctb[i].rcd_bitmap, 0, MAX_ADN_BITMAP);
434 break;
435 case FDN:
436 phb_ctb[i].rcd_bitmap = fdn_bitmap;
437 memset(phb_ctb[i].rcd_bitmap, 0, MAX_FDN_BITMAP);
438 break;
439 }
440 break;
441 case ADN_FDN:
442 pb_init_ctb(i);
443 break;
444 default:
445 break;
446 }
447 }
448 }
449
450 /*
451 +--------------------------------------------------------------------+
452 | PROJECT: MMI-Framework (8417) MODULE: PHB |
453 | STATE : code ROUTINE: pb_reset |
454 +--------------------------------------------------------------------+
455
456 PURPOSE : Invalidate phonebook buffered in RAM
457
458 */
459
460 void pb_reset (void)
461 {
462 TRACE_FUNCTION("pb_reset()");
463
464 pb_write_eeprom();
465
466 fdn_mode = NO_OPERATION; /* some more stuff may be needed */
467 /* set fdn_classtype to default value */
468 fdn_classtype = CLASS_VceDatFaxSms;
469 fdn_input_classtype = fdn_classtype;
470 cmhPHB_StatIndication ( PHB_UNKNOWN, CME_ERR_NotPresent, TRUE );
471 }
472
473 /*
474 +--------------------------------------------------------------------+
475 | PROJECT: MMI-Framework (8417) MODULE: PHB |
476 | STATE : code ROUTINE: pb_create_memory |
477 +--------------------------------------------------------------------+
478
479
480 PURPOSE : Find the next free entry
481
482 */
483
484 T_PHB_RETURN pb_create_memory(SHORT *index)
485 {
486 int i;
487
488 /* TRACE_FUNCTION("pb_create_memory()"); */
489
490 for (i=0; i<MAX_AFB_RECORDS; i++)
491 {
492 if (phb_element[i].free EQ PHB_ELEMENT_FREE)
493 {
494 memset ((char *)&phb_element[i].entry, 0xff, sizeof (T_AFB_RECORD));
495 phb_element[i].free = PHB_ELEMENT_USED;
496 *index = i;
497 return PHB_OK;
498 }
499 }
500
501 return PHB_FULL;
502 }
503
504
505 /*
506 +--------------------------------------------------------------------+
507 | PROJECT: MMI-Framework (8417) MODULE: PHB |
508 | STATE : code ROUTINE: pb_create_l_memory |
509 +--------------------------------------------------------------------+
510
511
512 PURPOSE : Find the next free entry
513
514 */
515
516 T_PHB_RETURN pb_create_l_memory(SHORT *index)
517 {
518 SHORT i;
519
520 /* TRACE_FUNCTION("pb_create_l_memory()"); */
521
522 for (i=0; i<MAX_RDM_RECORDS; i++)
523 {
524 if (phb_l_element[i].free EQ PHB_ELEMENT_FREE)
525 {
526 memset ((char *)&phb_l_element[i].entry, 0xff, sizeof (T_RDM_RECORD));
527 phb_l_element[i].free = PHB_ELEMENT_USED;
528 *index = i;
529 return PHB_OK;
530 }
531 }
532
533 return PHB_FULL;
534 }
535
536
537 /*
538 +--------------------------------------------------------------------+
539 | PROJECT: MMI-Framework (8417) MODULE: PHB |
540 | STATE : code ROUTINE: pb_read_ecc |
541 +--------------------------------------------------------------------+
542
543
544 PURPOSE : Build emergency call phonebook.
545
546 */
547 T_PHB_RETURN pb_read_ecc (USHORT error, UBYTE ecc_len, UBYTE *sim_ecc)
548 {
549 UBYTE *data_ptr;
550 int i;
551
552 TRACE_FUNCTION ("pb_read_ecc()");
553
554 if (fdn_mode != NO_OPERATION)
555 return PHB_OK;
556
557 /* If SIM card is not active, the emergency call numbers are read from EEPROM */
558 if ( ( error EQ SIM_CAUSE_OTHER_ERROR )
559 OR ( error EQ SIM_CAUSE_CARD_REMOVED)
560 OR ( error >= SIM_CAUSE_PARAM_WRONG AND error <= SIM_CAUSE_DRV_TEMPFAIL) )
561 {
562 pb_read_eeprom_ecc();
563 }
564
565 /* SIM card is active, the emergency call numbers are read from SIM card */
566 else
567 {
568 /* if SIM ECC data is not empty, copy SIM ECC data to phonebook */
569 if ( strcmp((CHAR*)sim_ecc,"") )
570 {
571 phb_ctb[ECC].mem = SIM_MEMORY;
572 data_ptr = sim_ecc;
573 phb_ctb[ECC].max_rcd = (SHORT)((ecc_len/3) > MAX_ECC_RCD)? MAX_ECC_RCD: ecc_len/3;
574
575 phb_ctb[ECC].type = ECC;
576 phb_ctb[ECC].first_trcd = UNUSED_INDEX;
577
578 /* Read emergency call number */
579 for (i=0; i<MAX_ECC_RCD; i++)
580 {
581 pb_copy_ecc_entry (data_ptr, (UBYTE)i);
582 data_ptr += 3;
583 }
584 }
585 }
586
587 return PHB_OK;
588 }
589
590
591 /*
592 +----------------------------------------------------------------------+
593 | PROJECT: MMI-Framework (8417) MODULE: PHB |
594 | STATE : code ROUTINE: pb_read_sim |
595 +----------------------------------------------------------------------+
596
597
598 PURPOSE : SIM card informs the numbers of phonebook record.
599
600 */
601
602 BOOL pb_read_sim(USHORT data_id, UBYTE rcd_num, UBYTE len)
603 {
604 SHORT table_id;
605
606 TRACE_FUNCTION ("pb_read_sim()");
607
608 table_id = psaSIM_atbNewEntry();
609
610 if(table_id NEQ NO_ENTRY)
611 {
612 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
613 simShrdPrm.atb[table_id].accType = ACT_RD_REC;
614 simShrdPrm.atb[table_id].reqDataFld = data_id;
615 simShrdPrm.atb[table_id].recNr = rcd_num;
616 if (rcd_num EQ 1)
617 simShrdPrm.atb[table_id].dataLen = NOT_PRESENT_8BIT;
618 else
619 simShrdPrm.atb[table_id].dataLen = len;
620 simShrdPrm.atb[table_id].exchData = data;
621 simShrdPrm.atb[table_id].rplyCB = pb_read_cb;
622
623 simShrdPrm.aId = table_id;
624
625 if (pause_pb_reading_while_EXT_reading EQ TRUE) /* Read request must be paused while EXT is read */
626 {
627 paused_table_id = simShrdPrm.aId; /* save the aId for later SIM Access */
628 }
629 else
630 {
631 if(psaSIM_AccessSIMData() < 0)
632 {
633 TRACE_EVENT("FATAL ERROR");
634 return FALSE;
635 }
636 }
637 }
638 else
639 return FALSE;
640
641 return TRUE;
642 }
643
644
645
646 /*
647 +----------------------------------------------------------------------+
648 | PROJECT: MMI-Framework (8417) MODULE: PHB |
649 | STATE : code ROUTINE: pb_read_sim_ext |
650 +----------------------------------------------------------------------+
651
652
653 PURPOSE : SIM card informs the numbers of phonebook record.
654
655 */
656
657 #ifdef PHONEBOOK_EXTENSION
658 void pb_read_sim_ext(USHORT data_id, UBYTE rcd_num)
659 {
660 SHORT table_id;
661
662 TRACE_FUNCTION ("pb_read_sim_ext()");
663
664 table_id = psaSIM_atbNewEntry();
665
666 if(table_id NEQ NO_ENTRY)
667 {
668 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
669 simShrdPrm.atb[table_id].accType = ACT_RD_REC;
670 simShrdPrm.atb[table_id].reqDataFld = data_id;
671 simShrdPrm.atb[table_id].recNr = rcd_num;
672 simShrdPrm.atb[table_id].dataLen = 13;
673 simShrdPrm.atb[table_id].exchData = data;
674 simShrdPrm.atb[table_id].rplyCB = pb_read_ext_cb;
675
676 simShrdPrm.aId = table_id;
677
678 pause_pb_reading_while_EXT_reading = TRUE; /* Suspend further ADN reading while EXT is read */
679
680 if(psaSIM_AccessSIMData() < 0)
681 {
682 TRACE_EVENT("pb_read_sim_ext (): FATAL ERROR");
683 }
684 }
685 }
686 #endif
687
688
689
690 /*
691 +----------------------------------------------------------------------+
692 | PROJECT: MMI-Framework (8417) MODULE: PHB |
693 | STATE : code ROUTINE: pb_init_sync_sim |
694 +----------------------------------------------------------------------+
695
696
697 PURPOSE : Sync the local LDN entries to SIM
698 */
699
700
701 BOOL pb_init_sync_sim(UBYTE type)
702 {
703 TRACE_FUNCTION ("pb_init_sync_sim()");
704
705 switch (type)
706 {
707 case LDN:
708 break;
709 default: /* Only supported for LDN */
710 return FALSE;
711 }
712
713 if (phb_ctb[type].service == ALLOCATED_AND_ACTIVATED
714 AND phb_ctb[type].mem != NO_PHB_ENTRY)
715 {
716 if (max_sim_LDN_records) /* start with oldest record */
717 return (pb_prepare_sync_sim(type, max_sim_LDN_records));
718 }
719 return FALSE;
720 }
721
722
723 /*
724 +----------------------------------------------------------------------+
725 | PROJECT: MMI-Framework (8417) MODULE: PHB |
726 | STATE : code ROUTINE: pb_prepare_sync_sim |
727 +----------------------------------------------------------------------+
728
729
730 PURPOSE : Sync the local LDN entries to SIM
731 */
732
733 BOOL pb_prepare_sync_sim(UBYTE type, UBYTE rcd_num)
734 {
735 T_PHB_RECORD entry;
736 T_PHB_RETURN sim_result;
737 UBYTE tag_len;
738
739 TRACE_FUNCTION ("pb_prepare_sync_sim()");
740
741 switch (type)
742 {
743 case LDN:
744 break;
745 default:
746 return FALSE;
747 }
748
749 memset(data, 0xFF, sizeof(data));
750
751 if (pb_read_phys_record( type, rcd_num, &entry) NEQ PHB_OK)
752 {
753 sim_result = pb_sync_sim(type, rcd_num); /* Write an empty record */
754 }
755 else
756 {
757 tag_len = MINIMUM ( phb_ctb[type].alpha_len, entry.tag_len );
758 memcpy(data, entry.tag, tag_len);
759 data[phb_ctb[type].alpha_len] = entry.len+1;
760 /*#if PHONEBOOK_EXTENSION*/
761 #if 0
762 if (entry.number[10] NEQ 0xFF)
763 {
764 data[phb_ctb[type].alpha_len] = 11; /* max. length */
765 }
766 else
767 {
768 data[phb_ctb[type].alpha_len] = entry.len+1;
769 }
770 #else
771 data[phb_ctb[type].alpha_len] = entry.len+1;
772 #endif
773 data[phb_ctb[type].alpha_len+1] = entry.ton_npi;
774 memcpy((char *)&data[phb_ctb[type].alpha_len+2],
775 (char *)entry.number, 10);
776 data[phb_ctb[type].alpha_len+12] = entry.cc_id;
777
778 /*#ifdef PHONEBOOK_EXTENSION*/
779 #if 0
780 if (entry->number[10] NEQ 0xFF)
781 {
782 file_id = pb_get_ext_file_id (type);
783 if (old_ext_rcd_num NEQ 0xFF)
784 {
785 /* use the old extention record */
786 phb_element[new_index].entry.ext_rcd_num = old_ext_rcd_num;
787 }
788 else
789 {
790 phb_element[new_index].entry.ext_rcd_num = pb_get_ext_record_number (type);
791 }
792 data[phb_ctb[type].alpha_len+13] = phb_element[new_index].entry.ext_rcd_num;
793 }
794 /* only number extention or subaddress could be store */
795 else if (entry->subaddr[0] NEQ 0xFF)
796 {
797 file_id = pb_get_ext_file_id (type);
798 if (old_ext_rcd_num NEQ 0xFF)
799 {
800 /* use the old extention record */
801 phb_element[new_index].entry.ext_rcd_num = old_ext_rcd_num;
802 }
803 else
804 {
805 phb_element[new_index].entry.ext_rcd_num = pb_get_ext_record_number (0xFF);
806 }
807 data[phb_ctb[type].alpha_len+13] = phb_element[new_index].entry.ext_rcd_num;
808 }
809 #endif
810 sim_result = pb_sync_sim(type, rcd_num); /* Record is always 1 for cyclic files */
811
812 /*#ifdef PHONEBOOK_EXTENSION*/
813 #if 0
814 if (sim_result NEQ PHB_FAIL)
815 {
816 if (phb_element[new_index].entry.ext_rcd_num NEQ 0xFF)
817 {
818 pb_prepare_ext_data (phb_element[new_index].entry.number,
819 phb_element[new_index].entry.len,
820 phb_element[new_index].entry.subaddr,
821 10,
822 file_id);
823 sim_result = pb_write_sim_ext(file_id, phb_element[new_index].entry.ext_rcd_num);
824 }
825 else if (old_ext_rcd_num NEQ 0xFF)
826 {
827 /* delete the old extention record */
828 pb_rem_ext_record_flag (type, old_ext_rcd_num);
829 pb_prepare_ext_data (NULL, 0, NULL, 0, file_id);
830 sim_result = pb_write_sim_ext(SIM_EXT1, old_ext_rcd_num);
831 }
832 }
833 #endif /* PHONEBOOK_EXTENSION */
834 }
835 if (sim_result NEQ PHB_FAIL)
836 return (TRUE);
837 return TRUE;
838 }
839
840
841 /*
842 +----------------------------------------------------------------------+
843 | PROJECT: MMI-Framework (8417) MODULE: PHB |
844 | STATE : code ROUTINE: pb_sync_sim |
845 +----------------------------------------------------------------------+
846
847
848 PURPOSE : Sync the local LDN entries to SIM
849 */
850
851 BOOL pb_sync_sim (UBYTE type, UBYTE rcd_num)
852 {
853 SHORT table_id;
854 USHORT data_id;
855
856 TRACE_FUNCTION ("pb_sync_sim()");
857
858 switch (type)
859 {
860 case LDN:
861 data_id = SIM_LND;
862 break;
863 default:
864 return FALSE;
865 }
866
867 table_id = psaSIM_atbNewEntry();
868 if (table_id EQ NO_ENTRY)
869 {
870 TRACE_ERROR ("pb_sync_sim(): no more table entries");
871 return (FALSE);
872 }
873
874 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
875 simShrdPrm.atb[table_id].accType = ACT_WR_REC;
876 simShrdPrm.atb[table_id].reqDataFld = data_id;
877 simShrdPrm.atb[table_id].recNr = rcd_num;
878 simShrdPrm.atb[table_id].dataLen = phb_ctb[type].alpha_len + 14;
879 simShrdPrm.atb[table_id].exchData = data;
880 simShrdPrm.atb[table_id].rplyCB = pb_sync_sim_cb;
881
882 simShrdPrm.aId = table_id;
883
884
885 if(psaSIM_AccessSIMData() < 0)
886 {
887 return (FALSE);
888 }
889
890 phb_stat = PHB_BUSY;
891 cmhPHB_StatIndication ( PHB_BUSY, CME_ERR_NotPresent, TRUE );
892
893 /* return (PHB_EXCT);*/
894 return (TRUE);
895 }
896
897
898
899
900 /*
901 +------------------------------------------------------------------+
902 | PROJECT : MMI-Framework (8417) MODULE : PHB |
903 | STATE : code ROUTINE : pb_sync_sim_cb |
904 +------------------------------------------------------------------+
905
906
907 PURPOSE : Call back for sync phonebook in SIM card.
908
909 */
910
911 void pb_sync_sim_cb(SHORT table_id)
912 {
913 UBYTE type;
914 USHORT type_id;
915 UBYTE rcd_num;
916
917 TRACE_FUNCTION("pb_sync_sim_cb()");
918
919 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
920
921 if (simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR)
922 {
923 TRACE_ERROR("pb_sync_sim_cb(): error for writing");
924 /* return; */ /* dont stop writing here if one record fails since must reach¬
925 pb_finish_sync_sim to deactivate the sim */
926 }
927
928 /* Inform the data of record */
929 switch (simShrdPrm.atb[table_id].reqDataFld)
930 {
931 case SIM_LND: /* Up to now only LDN supported */
932 type = LDN;
933 type_id = SIM_LND;
934 break;
935 default:
936 TRACE_FUNCTION("pb_sync_sim_cb() invalid callback");
937 return;
938 }
939
940 rcd_num = simShrdPrm.atb[table_id].recNr;
941 if (--rcd_num)
942 {
943 pb_prepare_sync_sim(type, rcd_num); /* sync next record */
944 return;
945 }
946 else /* Last record copied to SIM */
947 {
948 pb_finish_sync_sim();
949 }
950 return;
951 }
952
953
954
955 /*
956 +---------------------------------------------------------------------+
957 | PROJECT : MMI-Framework (8417) MODULE : PHB |
958 | STATE : code ROUTINE : pb_finish_sync_sim |
959 +---------------------------------------------------------------------+
960
961
962 PURPOSE : Call back for sync phonebook in SIM card.
963
964 */
965
966 void pb_finish_sync_sim()
967 {
968 phb_stat = PHB_READY;
969
970 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, TRUE );
971
972 pb_reset();
973 pb_init();
974
975 simShrdPrm.synCs = SYNC_DEACTIVATE; /* This was moved from pb_sync_sim_ldn */
976 psaSIM_SyncSIM();
977
978 return;
979 }
980
981
982
983
984
985 /*
986 +-------------------------------------------------------------------+
987 | PROJECT : MMI-Framework (8417) MODULE : PHB |
988 | STATE : code ROUTINE : pb_copy_sim_entry|
989 +-------------------------------------------------------------------+
990
991
992 PURPOSE : SIM card informs the numbers of phonebook record.
993
994 */
995
996 void pb_copy_sim_entry(SHORT cur_index)
997 {
998 UBYTE *ptr;
999 UBYTE max_tag_len;
1000 #ifdef PHONEBOOK_EXTENSION
1001 USHORT file_id;
1002 #endif
1003
1004 TRACE_FUNCTION ("pb_copy_sim_entry()");
1005
1006 ptr = data;
1007 max_tag_len = MINIMUM (phb_ctb[phb_element[cur_index].type].alpha_len,
1008 PHB_MAX_TAG_LEN);
1009 phb_element[cur_index].entry.tag_len = (UBYTE)pb_get_entry_len(ptr, max_tag_len);
1010 memset(phb_element[cur_index].entry.tag, 0xFF, PHB_MAX_TAG_LEN); /* init the tag value */
1011 memcpy ( (char*)phb_element[cur_index].entry.tag,
1012 (char*)ptr,
1013 phb_element[cur_index].entry.tag_len );
1014
1015 ptr += phb_ctb[phb_element[cur_index].type].alpha_len;
1016 phb_element[cur_index].entry.len = *(ptr++) - 1;
1017 phb_element[cur_index].entry.ton_npi = *ptr++;
1018 memset(phb_element[cur_index].entry.number, 0xFF, PHB_PACKED_NUM_LEN);
1019 memcpy( (char*)phb_element[cur_index].entry.number, (char*)ptr, phb_element[cur_index].entry.len );
1020 ptr += 10;
1021 phb_element[cur_index].entry.cc_id = *ptr++;
1022
1023 #ifdef PHONEBOOK_EXTENSION
1024 if (*ptr != 0xFF) /* check for extention records */
1025 {
1026 file_id = pb_get_ext_file_id(phb_element[cur_index].type);
1027 if (file_id != 0xFFFF)
1028 {
1029 phb_element[cur_index].entry.ext_rcd_num = (UBYTE)*ptr;
1030 ext_index = cur_index;
1031 max_ext_chain_reads=5; /* Limit the number of additional EXT reads per ADN record to avoid a possible endless loop */
1032 pb_read_sim_ext(file_id, phb_element[cur_index].entry.ext_rcd_num);
1033 }
1034 }
1035 else
1036 {
1037 phb_element[cur_index].entry.ext_rcd_num = 0xFF;
1038 }
1039 #endif
1040 }
1041
1042
1043 /*
1044 +-------------------------------------------------------------------+
1045 | PROJECT : MMI-Framework (8417) MODULE : PHB |
1046 | STATE : code ROUTINE : pb_copy_sim_entry|
1047 +-------------------------------------------------------------------+
1048
1049
1050 PURPOSE : SIM card informs the numbers of phonebook record.
1051
1052 */
1053
1054 void pb_copy_sim_ldn_entry(SHORT cur_index)
1055 {
1056 UBYTE *ptr;
1057 UBYTE max_tag_len;
1058 #ifdef PHONEBOOK_EXTENSION
1059 /* USHORT file_id;*/
1060 #endif
1061
1062 TRACE_FUNCTION ("pb_copy_sim_ldn_entry()");
1063
1064 ptr = data;
1065 max_tag_len = MINIMUM (phb_ctb[phb_l_element[cur_index].type].alpha_len,
1066 PHB_MAX_TAG_LEN);
1067 phb_l_element[cur_index].entry.tag_len = (UBYTE)pb_get_entry_len(ptr, max_tag_len);
1068 memset(phb_l_element[cur_index].entry.tag, 0xFF, PHB_MAX_TAG_LEN); /* init the tag value */
1069 memcpy ( (char*)phb_l_element[cur_index].entry.tag,
1070 (char*)ptr,
1071 phb_l_element[cur_index].entry.tag_len );
1072
1073 ptr += phb_ctb[phb_l_element[cur_index].type].alpha_len;
1074 phb_l_element[cur_index].entry.len = *(ptr++) - 1;
1075 phb_l_element[cur_index].entry.ton_npi = *ptr++;
1076 memset(phb_l_element[cur_index].entry.number, 0xFF, PHB_PACKED_NUM_LEN);
1077 memcpy( (char*)phb_l_element[cur_index].entry.number, (char*)ptr, 10 );
1078 ptr += 10;
1079 phb_l_element[cur_index].entry.cc_id = *ptr++;
1080
1081 phb_l_element[cur_index].entry.year = 0xff; /* This is not on SIM */
1082 phb_l_element[cur_index].entry.month = 0xff;
1083 phb_l_element[cur_index].entry.day = 0xff;
1084 phb_l_element[cur_index].entry.hour = 0xff;
1085 phb_l_element[cur_index].entry.minute = 0xff;
1086 phb_l_element[cur_index].entry.second = 0xff;
1087
1088 /*#ifdef PHONEBOOK_EXTENSION */
1089 #if 0
1090 if (*ptr != 0xFF) /* check for extention records */
1091 {
1092 file_id = pb_get_ext_file_id(phb_l_element[cur_index].type);
1093 if (file_id != 0xFFFF)
1094 {
1095 phb_l_element[cur_index].entry.ext_rcd_num = (UBYTE)*ptr;
1096 ext_index = cur_index;
1097 pb_read_sim_ext(file_id, phb_l_element[cur_index].entry.ext_rcd_num);
1098 }
1099 }
1100 else
1101 {
1102 phb_l_element[cur_index].entry.ext_rcd_num = 0xFF;
1103 }
1104 #endif
1105 }
1106
1107
1108 /*
1109 +---------------------------------------------------------------------+
1110 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1111 | STATE : code ROUTINE: pb_read_sim_record |
1112 +---------------------------------------------------------------------+
1113
1114
1115 PURPOSE : Build emergency call phonebook.
1116
1117 */
1118
1119 T_PHB_RETURN pb_read_sim_record(UBYTE type, USHORT type_id, UBYTE rcd_num)
1120 {
1121 SHORT index;
1122 UBYTE n,m;
1123
1124 /* TRACE_FUNCTION ("pb_read_sim_record()");*/
1125
1126 if (phb_ctb[type].used_rcd >= phb_ctb[type].max_rcd)
1127 {
1128 TRACE_FUNCTION("Used rcd full!");
1129 return PHB_FULL;
1130 }
1131
1132 if (type NEQ LDN)
1133 {
1134 /* search a free element in phonebook element table */
1135 if (pb_create_memory(&index) NEQ PHB_OK)
1136 {
1137 TRACE_FUNCTION("Memory full");
1138 pb_read_eeprom_req();
1139 return PHB_FULL;
1140 }
1141
1142 phb_ctb[type].used_rcd++;
1143 n = (UBYTE)(rcd_num-1)/8;
1144 m = (rcd_num-1)%8;
1145 phb_ctb[type].rcd_bitmap[n] |= 0x01 << m;
1146 phb_element[index].type = type;
1147 phb_element[index].entry.index = rcd_num;
1148
1149 pb_copy_sim_entry(index);
1150
1151 pb_record_sort(index);
1152 pb_alpha_sort(index);
1153 pb_num_sort(index);
1154
1155 if ((type EQ ADN) OR (type EQ FDN))
1156 {
1157 pb_malpha_sort(index);
1158 pb_mnum_sort(index);
1159 }
1160 }
1161 else /* special handling for LDN entries from SIM */
1162 {
1163 if (pb_create_l_memory(&index) NEQ PHB_OK)
1164 {
1165 TRACE_FUNCTION("Memory full");
1166 pb_read_eeprom_req();
1167 return PHB_OK;
1168 }
1169 phb_ctb[type].used_rcd++;
1170 phb_l_element[index].type = type;
1171 phb_l_element[index].entry.index = rcd_num;
1172
1173 pb_copy_sim_ldn_entry(index);
1174
1175 pb_l_record_sort(index);
1176 /* pb_l_alpha_sort(index);*//* not possible with RDM Structure */
1177 /* pb_l_num_sort(index);*/
1178 }
1179
1180 return PHB_OK;
1181 }
1182
1183
1184 /*
1185 +---------------------------------------------------------------------+
1186 | PROJECT: MODULE: PHB |
1187 | STATE : code ROUTINE: pb_get_ext_file_id |
1188 +---------------------------------------------------------------------+
1189
1190
1191 PURPOSE : Find and gives the extention SIM file ID for the
1192 phonebook entry.
1193
1194 */
1195 #ifdef PHONEBOOK_EXTENSION
1196 LOCAL USHORT pb_get_ext_file_id (UBYTE pb_type)
1197 {
1198 switch (pb_type)
1199 {
1200 case 0xFF:
1201 case ADN:
1202 case LDN:
1203 return (SIM_EXT1);
1204
1205 case FDN:
1206 return (SIM_EXT2);
1207
1208 case SDN:
1209 return (SIM_EXT3);
1210
1211 case BDN:
1212 return (SIM_EXT4);
1213
1214 default:
1215 TRACE_ERROR ("pb_get_free_ext_record(): invalid type");
1216 return (0xFFFF);
1217 }
1218 }
1219
1220
1221 /*
1222 +-----------------------------------------------------------------------+
1223 | PROJECT: MODULE: PHB |
1224 | STATE : code ROUTINE: pb_rem_ext_record_flag |
1225 +-----------------------------------------------------------------------+
1226
1227
1228 PURPOSE : Removes the flag for the extention record.
1229
1230 */
1231
1232 LOCAL void pb_rem_ext_record_flag (UBYTE pb_type, UBYTE rcd_num)
1233 {
1234 UBYTE *rcd_bitmap;
1235 UBYTE pos, bit, len;
1236
1237 switch (pb_type)
1238 {
1239 case 0xFF:
1240 case ADN:
1241 rcd_bitmap = phb_ext_records[EXT1].rcd_bitmap;
1242 len = MAX_EXT1_BITMAP;
1243 break;
1244
1245 case FDN:
1246 rcd_bitmap = phb_ext_records[EXT2].rcd_bitmap;
1247 len = MAX_EXT2_BITMAP;
1248 break;
1249
1250 case BDN:
1251 case SDN:
1252 default:
1253 TRACE_ERROR ("pb_rem_free_ext_record(): invalid type");
1254 return;
1255 }
1256
1257 pos = (UBYTE)(rcd_num - 1) / 8;
1258 bit = (rcd_num - 1) % 8;
1259
1260 rcd_bitmap[pos] &= (UBYTE)(~(1u << bit));
1261
1262 }
1263
1264
1265 /*
1266 +-------------------------------------------------------------------------+
1267 | PROJECT: MODULE: PHB |
1268 | STATE : code ROUTINE: pb_rem_ext_record_number |
1269 +-------------------------------------------------------------------------+
1270
1271
1272 PURPOSE : Gives the extention record number for the phonebook entry.
1273
1274 */
1275
1276 LOCAL UBYTE pb_get_ext_record_number (UBYTE pb_type)
1277 {
1278 UBYTE *rcd_bitmap;
1279 UBYTE len, pos, bit, rcd_num;
1280
1281 switch (pb_type)
1282 {
1283 case 0xFF:
1284 case ADN:
1285 rcd_bitmap = phb_ext_records[EXT1].rcd_bitmap;
1286 len = MAX_EXT1_BITMAP;
1287 break;
1288
1289 case FDN:
1290 rcd_bitmap = phb_ext_records[EXT2].rcd_bitmap;
1291 len = MAX_EXT2_BITMAP;
1292 break;
1293
1294 case BDN:
1295 case SDN:
1296 default:
1297 TRACE_ERROR ("pb_get_free_ext_number(): invalid type");
1298 return (0xFF);
1299 }
1300
1301 for (pos = 0; pos < len; pos++)
1302 {
1303 if (~(rcd_bitmap[pos]))
1304 {
1305 bit = 0;
1306 while (rcd_bitmap[pos] & (1 << bit))
1307 {
1308 bit++;
1309 if (bit EQ 7)
1310 {
1311 TRACE_ERROR ("pb_get_free_ext_number (): NOT POSSIBLE");
1312 return (0);
1313 }
1314 }
1315 rcd_bitmap[pos] |= (1 << bit);
1316 rcd_num = (pos * 8) + bit + 1;
1317 return (rcd_num);
1318 }
1319 }
1320 TRACE_ERROR ("pb_get_free_ext_record(): no more extention records free");
1321
1322 return (0xFF);
1323 }
1324
1325
1326 /*
1327 +-----------------------------------------------------------------------+
1328 | PROJECT: MODULE: PHB |
1329 | STATE : code ROUTINE: pb_read_ext_records |
1330 +-----------------------------------------------------------------------+
1331
1332
1333 PURPOSE : Store the extention record flag and read the next record.
1334
1335 */
1336
1337 LOCAL void pb_read_ext_records (T_PHB_EXT_TYPE type,
1338 USHORT sim_id,
1339 SHORT table_id)
1340 {
1341 UBYTE rcd_num;
1342 UBYTE n, m;
1343
1344 rcd_num = simShrdPrm.atb[table_id].recNr;
1345
1346 if (rcd_num EQ 1)
1347 {
1348 phb_ext_records[type].max_rcd = simShrdPrm.atb[table_id].recMax;
1349 }
1350
1351 /* If this record is not empty ==> set used flag */
1352 if (data[0] NEQ 0xFF)
1353 {
1354 n = (UBYTE)(rcd_num - 1) / 8;
1355 m = (rcd_num - 1) % 8;
1356 phb_ext_records[type].rcd_bitmap[n] |= (0x01 << m);
1357 }
1358
1359 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
1360
1361 if (rcd_num < phb_ext_records[type].max_rcd)
1362 {
1363 pb_read_sim(sim_id, ++rcd_num, simShrdPrm.atb[table_id].dataLen);
1364 }
1365 else
1366 {
1367 pb_read_sim_req();
1368 }
1369 }
1370 #endif
1371
1372 /*
1373 +---------------------------------------------------------------------+
1374 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1375 | STATE : code ROUTINE: pb_read_cb |
1376 +---------------------------------------------------------------------+
1377
1378
1379 PURPOSE : read sim callback function
1380
1381 */
1382 void pb_read_cb(SHORT table_id)
1383 {
1384 UBYTE type = NOT_PRESENT_8BIT;
1385 USHORT type_id;
1386 UBYTE rcd_num; /* record number */
1387
1388 TRACE_FUNCTION ("pb_read_cb()");
1389
1390 /* Inform the data of record */
1391 switch (simShrdPrm.atb[table_id].reqDataFld)
1392 {
1393 #ifdef PHONEBOOK_EXTENSION
1394 case SIM_EXT1:
1395 pb_read_ext_records (EXT1, SIM_EXT1, table_id);
1396 return;
1397
1398 case SIM_EXT2:
1399 pb_read_ext_records (EXT2, SIM_EXT2, table_id);
1400 return;
1401 #endif
1402 case SIM_ADN:
1403 type = ADN;
1404 type_id = SIM_ADN;
1405 break;
1406
1407 case SIM_FDN:
1408 type = FDN;
1409 type_id = SIM_FDN;
1410 break;
1411
1412 case SIM_LND: /* Support for SIM_LDN */
1413 type = LDN; /* Caution: different identifiers LDN and LND */
1414 type_id = SIM_LND;
1415 break;
1416
1417 case SIM_SDN:
1418 type = SDN;
1419 type_id = SIM_SDN;
1420 break;
1421
1422 case SIM_BDN:
1423 type = BDN;
1424 type_id = SIM_BDN;
1425 break;
1426
1427 case SIM_MSISDN:
1428 type = UPN;
1429 type_id = SIM_MSISDN;
1430 break;
1431
1432 default:
1433 TRACE_ERROR ("Invalid reqDataFld!");
1434 return;
1435
1436 }
1437 TRACE_EVENT_P1("Callback of SIM reading Phonebook: %d", type);
1438
1439 rcd_num = simShrdPrm.atb[table_id].recNr;
1440
1441
1442 if (rcd_num EQ 1)
1443 {
1444 if (type EQ LDN)
1445 {
1446 /* remember physical count for writing of correct number of LND on CFUN=0 */
1447 max_sim_LDN_records = simShrdPrm.atb[table_id].recMax;
1448 }
1449 phb_ctb[type].alpha_len = simShrdPrm.atb[table_id].dataLen - 14;
1450 phb_ctb[type].max_rcd = simShrdPrm.atb[table_id].recMax;
1451 }
1452
1453 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
1454
1455 /*
1456 * workaround for invalid phonebook entries (the entire entry is filled with 0x00)
1457 * this entries have been received which a very slow SIM
1458 * check if the Length of BCD number/SSC contents is 0x00 then discard
1459 */
1460
1461 /* If this record is not empty, this record is written in phonebook. */
1462 if((phb_ctb[type].max_rcd NEQ 0)
1463 AND ((*data NEQ 0xff) OR (*(data + phb_ctb[type].alpha_len + 2) NEQ 0xff))
1464 AND (*(data + phb_ctb[type].alpha_len) NEQ 0x00))
1465 {
1466 if (pb_read_sim_record(type, type_id, rcd_num) EQ PHB_FULL)
1467 {
1468 #ifdef SIM_TOOLKIT
1469 if (simShrdPrm.fuRef >= 0)
1470 {
1471 psaSAT_FUConfirm (simShrdPrm.fuRef, SIM_FU_SUCC_ADD);
1472 }
1473 #endif
1474 phb_stat = PHB_READY;
1475 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, TRUE );
1476 return;
1477 }
1478 }
1479
1480 if (rcd_num < phb_ctb[type].max_rcd)
1481 {
1482 pb_read_sim(type_id, ++rcd_num, simShrdPrm.atb[table_id].dataLen);
1483 }
1484 else
1485 pb_read_sim_req();
1486 }
1487
1488
1489
1490
1491 /*
1492 +---------------------------------------------------------------------+
1493 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1494 | STATE : code ROUTINE: pb_nibblecopy |
1495 +---------------------------------------------------------------------+
1496
1497
1498 PURPOSE : appends a packed BCD number to an existing entry.
1499 */
1500
1501 #ifdef PHONEBOOK_EXTENSION
1502 int pb_nibblecopy (UBYTE dest[], int destlen, UBYTE src[], int count)
1503 {
1504
1505 int i;
1506 int nibble;
1507
1508 int destnibble=destlen*2;
1509 if (destnibble)
1510 {
1511 if ((dest[destlen-1] & 0xF0) == 0xF0) /* check if there is space in last nibble */
1512 destnibble--;
1513 }
1514
1515 for ( i=0; i<count*2; i++ )
1516 {
1517 /* check if we access out of bounds */
1518 if (destnibble/2 >= PHB_PACKED_NUM_LEN)
1519 return PHB_PACKED_NUM_LEN;
1520
1521 /* get nibble */
1522 if (i%2 == 0)
1523 nibble = src[i/2] & 0x0F;
1524 else
1525 nibble = (src[i/2] & 0xF0) >> 4;
1526
1527 if (nibble == 0xF) /* end of number detected */
1528 break;
1529
1530 /* put nibble */
1531 if (destnibble%2 == 0)
1532 {
1533 dest[destnibble/2] &= 0xF0;
1534 dest[destnibble/2] |= nibble;
1535 }
1536 else
1537 {
1538 dest[destnibble/2] &= 0x0F;
1539 dest[destnibble/2] |= nibble << 4;
1540 }
1541
1542 destnibble++;
1543 }
1544 return destnibble/2 + destnibble%2; /* round up */
1545 }
1546 #endif
1547
1548
1549 /*
1550 +---------------------------------------------------------------------+
1551 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1552 | STATE : code ROUTINE: pb_read_ext_cb |
1553 +---------------------------------------------------------------------+
1554
1555
1556 PURPOSE : read sim callback function
1557
1558 */
1559
1560 #ifdef PHONEBOOK_EXTENSION
1561 void pb_read_ext_cb(SHORT table_id)
1562 {
1563 USHORT type_id;
1564 /* UBYTE buf[11];*/
1565 UBYTE data_len;
1566 UBYTE data_type;
1567
1568 TRACE_FUNCTION ("pb_read_ext_cb()");
1569
1570 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
1571
1572 if (simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR)
1573 {
1574 TRACE_EVENT_P1 ("SIM returned error 0x%04X", simShrdPrm.atb[table_id].errCode);
1575 }
1576 else
1577 {
1578 type_id = simShrdPrm.atb[table_id].reqDataFld;
1579
1580 /* If this extension record is not empty, it is written in phonebook. */
1581 data_type = data[0];
1582 data_len = data[1];
1583
1584 switch (data_type)
1585 {
1586 case 1: /* Called Party Subaddress */
1587 {
1588 int sa_len = 0;
1589 while (sa_len<PHB_PACKED_NUM_LEN) /* get length of possible already stored subaddr if more than one EXT is used */
1590 {
1591 if (phb_element[ext_index].entry.subaddr[sa_len] EQ 0xFF)
1592 break;
1593 else if ((phb_element[ext_index].entry.subaddr[sa_len] & 0xF0) EQ 0xF0)
1594 {
1595 sa_len++;
1596 break;
1597 }
1598 else
1599 sa_len++;
1600 }
1601
1602 pb_nibblecopy (phb_element[ext_index].entry.subaddr,
1603 sa_len,
1604 data + 2,
1605 data_len);
1606 }
1607 break;
1608
1609 case 2: /* Additional data */
1610 phb_element[ext_index].entry.len =
1611 pb_nibblecopy (phb_element[ext_index].entry.number,
1612 phb_element[ext_index].entry.len,
1613 data + 2,
1614 data_len);
1615 break;
1616
1617 default: /* unknown type */
1618 break;
1619 }
1620
1621 if (data[12] != 0xFF) /* check if a further EXT entry exists */
1622 {
1623 if (max_ext_chain_reads) /* limit reached? */
1624 {
1625 max_ext_chain_reads--;
1626 pb_read_sim_ext(type_id, data[12]);
1627 return;
1628 }
1629 }
1630 }
1631
1632 /* Continue reading the last by EXT interrupted phonebook */
1633 pause_pb_reading_while_EXT_reading = FALSE;
1634
1635 if (paused_table_id)
1636 {
1637 simShrdPrm.aId = paused_table_id;
1638 paused_table_id = 0;
1639 if(psaSIM_AccessSIMData() < 0)
1640 {
1641 TRACE_EVENT("FATAL ERROR");
1642 return;
1643 }
1644 }
1645 }
1646 #endif
1647
1648 /*
1649 +--------------------------------------------------------------------+
1650 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1651 | STATE : code ROUTINE: pb_read_eeprom_req |
1652 +--------------------------------------------------------------------+
1653
1654
1655 PURPOSE : Request to build phonebook.
1656
1657 */
1658 T_PHB_RETURN pb_read_eeprom_req(void)
1659 {
1660 UBYTE version;
1661 UBYTE i, n, m;
1662 SHORT index;
1663 USHORT max_rcd;
1664 EF_UPN *efupn;
1665
1666 TRACE_FUNCTION ("pb_read_eeprom_req()");
1667
1668 phb_ctb[ADN_FDN].mem = SIM_MEMORY;
1669 phb_ctb[ADN_FDN].type = ADN_FDN;
1670 if (phb_ctb[ADN].alpha_len)
1671 phb_ctb[ADN_FDN].alpha_len = phb_ctb[ADN].alpha_len;
1672 else
1673 phb_ctb[ADN_FDN].alpha_len = phb_ctb[FDN].alpha_len;
1674
1675 phb_ctb[ADN_FDN].max_rcd = phb_ctb[ADN].max_rcd + phb_ctb[FDN].max_rcd;
1676 phb_ctb[ADN_FDN].used_rcd = phb_ctb[ADN].used_rcd + phb_ctb[FDN].used_rcd;
1677
1678 if (read_flag)
1679 {
1680 phb_stat = PHB_READY;
1681 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, TRUE );
1682 return PHB_OK;
1683 }
1684
1685 /* Read Last Dialing Numbers */
1686
1687 if (phb_ctb[LDN].mem EQ NO_PHB_ENTRY) /* No phonebook loaded from SIM? */
1688 {
1689 phb_ctb[LDN].mem = TE_MEMORY;
1690 phb_ctb[LDN].type = LDN;
1691 phb_ctb[LDN].max_rcd = MAX_RDM_RECORDS/3;
1692 phb_ctb[LDN].used_rcd = 0;
1693 phb_ctb[LDN].first_rcd = UNUSED_INDEX;
1694 phb_ctb[LDN].first_trcd = UNUSED_INDEX;
1695 phb_ctb[LDN].first_nrcd = UNUSED_INDEX;
1696 phb_ctb[LDN].first_mtrcd = UNUSED_INDEX;
1697 phb_ctb[LDN].first_mnrcd = UNUSED_INDEX;
1698 }
1699 else
1700 {
1701 /* either: */
1702 /* phb_ctb[LDN].max_rcd = MAX_RDM_RECORDS/3;*//* adjust in case SIM_max_record was smaller than PCM_max_rcd */
1703 /* or: */
1704 ; /* use max_rcd as read from SIM. */
1705
1706 }
1707 if (imsiFlag EQ FALSE ) /* SIM has changed? */
1708 {
1709 memset (data, 0xFF, SIZE_EF_LDN);
1710 i=0;
1711 while (i < NR_EF_LDN)
1712 {
1713 if (pcm_WriteRecord((UBYTE *)EF_LDN_ID, /* Wipe entire LDN-PCM */
1714 (USHORT)(i+1),
1715 SIZE_EF_LDN,
1716 data) NEQ DRV_OK)
1717 break;
1718 i++;
1719 }
1720 }
1721 else
1722 { /* Merge timestamp with existing SIM-entries */
1723 BOOL all_records_match = TRUE;
1724 SHORT records_from_sim = phb_ctb[LDN].used_rcd; /* =0 in case of no records from SIM read */
1725 EF_LDN *p = (EF_LDN *)data;
1726
1727 index = phb_ctb[LDN].first_rcd;
1728 for (i=0; i<(UBYTE)phb_ctb[LDN].max_rcd; i++)
1729 {
1730 if ((i+1) > NR_EF_LDN)
1731 break; /* end of phonebook */
1732 if (pcm_ReadRecord((UBYTE *)EF_LDN_ID,
1733 (USHORT)(i+1),
1734 SIZE_EF_LDN,
1735 (UBYTE *)&data[0],
1736 &version,
1737 &max_rcd) NEQ DRV_OK)
1738 break; /* read error */
1739 else
1740 {
1741 if (p->len NEQ 0 AND p->len NEQ 0xFF)
1742 {
1743 if ((i+1) <= records_from_sim)
1744 {
1745 if (index EQ UNUSED_INDEX)
1746 {
1747 all_records_match = FALSE;
1748 break;
1749 }
1750 if ( !memcmp((char *)phb_l_element[index].entry.number, (char *)&p->dldNum, 10)
1751 AND phb_l_element[index].entry.ton_npi EQ p->numTp
1752 AND phb_l_element[index].entry.len EQ p->len
1753 AND phb_l_element[index].entry.cc_id EQ p->ccp) /* Number matches? */
1754 {
1755 pb_copy_ldn_record(index, 0); /* then update the record with Timestamps and cc_id from PCM */
1756 }
1757 else
1758 {
1759 all_records_match = FALSE; /* one (or more) record failed */
1760 break; /* stop processing of further records */
1761 }
1762 index = phb_l_element[index].next_rcd;
1763 }
1764 else /* PCM has more entries than on SIM */
1765 {
1766 /* search a free element in phonebook element table */
1767 if (pb_create_l_memory(&index) NEQ PHB_OK)
1768 return PHB_FULL;
1769
1770 phb_ctb[LDN].used_rcd++;
1771 phb_l_element[index].type = LDN;
1772 phb_l_element[index].entry.index = i+1;
1773
1774 pb_copy_ldn_record((SHORT)index, 0);
1775 pb_l_record_sort(index);
1776 }
1777 }
1778 }
1779 }
1780 if (all_records_match NEQ TRUE) /* some elements did not match */
1781 {
1782 index = phb_ctb[LDN].first_rcd;
1783 for (i=0; i<phb_ctb[LDN].used_rcd; i++)
1784 {
1785 if (index EQ UNUSED_INDEX)
1786 {
1787 break;
1788 }
1789 phb_l_element[index].entry.year =
1790 phb_l_element[index].entry.month =
1791 phb_l_element[index].entry.day =
1792 phb_l_element[index].entry.hour =
1793 phb_l_element[index].entry.minute =
1794 phb_l_element[index].entry.second = 0xFF; /* remove previous merged data from PCM */
1795 index = phb_l_element[index].next_rcd;
1796 }
1797 }
1798 }
1799
1800
1801 /* Read Last received Numbers from EEPROM */
1802 phb_ctb[LRN].mem = TE_MEMORY;
1803 phb_ctb[LRN].type = LRN;
1804 phb_ctb[LRN].max_rcd = MAX_RDM_RECORDS/3;
1805 phb_ctb[LRN].used_rcd = 0;
1806 phb_ctb[LRN].first_rcd = UNUSED_INDEX;
1807 phb_ctb[LRN].first_trcd = UNUSED_INDEX;
1808 phb_ctb[LRN].first_nrcd = UNUSED_INDEX;
1809 phb_ctb[LRN].first_mtrcd = UNUSED_INDEX;
1810 phb_ctb[LRN].first_mnrcd = UNUSED_INDEX;
1811
1812 if (imsiFlag EQ FALSE )
1813 {
1814 memset (data, 0xFF, SIZE_EF_LRN);
1815 i=0;
1816 while (i < NR_EF_LRN)
1817 {
1818 if (pcm_WriteRecord((UBYTE *)EF_LRN_ID, /* Wipe entire LRN-PCM */
1819 (USHORT)(i+1),
1820 SIZE_EF_LRN,
1821 data) NEQ DRV_OK)
1822 break;
1823 i++;
1824 }
1825 }
1826 else
1827 {
1828 EF_LRN *p = (EF_LRN *)data;
1829 for (i=0; i<(UBYTE)phb_ctb[LRN].max_rcd; i++)
1830 {
1831 if ((i+1) > NR_EF_LRN)
1832 break;
1833 if (pcm_ReadRecord((UBYTE *)EF_LRN_ID,
1834 (USHORT)(i+1),
1835 SIZE_EF_LRN,
1836 (UBYTE *)&data[0],
1837 &version,
1838 &max_rcd) NEQ DRV_OK)
1839 break;
1840 else
1841 {
1842 if (p->len NEQ 0 AND p->len NEQ 0xFF)
1843 {
1844 /* search a free element in phonebook element table */
1845 if (pb_create_l_memory(&index) NEQ PHB_OK)
1846 return PHB_FULL;
1847
1848 phb_ctb[LRN].used_rcd++;
1849 phb_l_element[index].type = LRN;
1850 phb_l_element[index].entry.index = i+1;
1851
1852 pb_copy_lrn_record(index, 0);
1853 pb_l_record_sort(index);
1854 }
1855 }
1856 }
1857 }
1858
1859 /* Read Last missed Numbers from EEPROM */
1860 phb_ctb[LMN].mem = TE_MEMORY;
1861 phb_ctb[LMN].type = LMN;
1862 phb_ctb[LMN].max_rcd = MAX_RDM_RECORDS/3;
1863 phb_ctb[LMN].used_rcd = 0;
1864 phb_ctb[LMN].first_rcd = UNUSED_INDEX;
1865 phb_ctb[LMN].first_trcd = UNUSED_INDEX;
1866 phb_ctb[LMN].first_nrcd = UNUSED_INDEX;
1867 phb_ctb[LMN].first_mtrcd = UNUSED_INDEX;
1868 phb_ctb[LMN].first_mnrcd = UNUSED_INDEX;
1869
1870 if (imsiFlag EQ FALSE )
1871 {
1872 memset (data, 0xFF, SIZE_EF_LMN);
1873 i=0;
1874 while (i < NR_EF_LMN)
1875 {
1876 if (pcm_WriteRecord((UBYTE *)EF_LMN_ID, /* Wipe entire LMN-PCM */
1877 (USHORT)(i+1),
1878 SIZE_EF_LMN,
1879 data) NEQ DRV_OK)
1880 break;
1881 i++;
1882 }
1883 }
1884 else
1885 {
1886 EF_LMN *p = (EF_LMN *)data;
1887 for (i=0; i<(UBYTE)phb_ctb[LMN].max_rcd; i++)
1888 {
1889 if ((i+1) > NR_EF_LMN)
1890 break;
1891 if (pcm_ReadRecord((UBYTE *)EF_LMN_ID,
1892 (USHORT)(i+1),
1893 SIZE_EF_LMN,
1894 (UBYTE *)&data[0],
1895 &version,
1896 &max_rcd) NEQ DRV_OK)
1897 break;
1898 else
1899 {
1900 if (p->len NEQ 0 AND p->len NEQ 0xFF)
1901 {
1902 /* search a free element in phonebook element table */
1903 if (pb_create_l_memory(&index) NEQ PHB_OK)
1904 return PHB_FULL;
1905
1906 phb_ctb[LMN].used_rcd++;
1907 phb_l_element[index].type = LMN;
1908 phb_l_element[index].entry.index = i+1;
1909
1910 pb_copy_lmn_record(index, 0);
1911 pb_l_record_sort(index);
1912 }
1913 }
1914 }
1915 }
1916
1917 if (phb_ctb[UPN].mem EQ NO_PHB_ENTRY)
1918 {
1919 phb_ctb[UPN].mem = TE_MEMORY;
1920 phb_ctb[UPN].type = UPN;
1921 phb_ctb[UPN].max_rcd = NR_EF_UPN;
1922 phb_ctb[UPN].used_rcd = 0;
1923 phb_ctb[UPN].first_rcd = UNUSED_INDEX;
1924 phb_ctb[UPN].first_trcd = UNUSED_INDEX;
1925 phb_ctb[UPN].first_nrcd = UNUSED_INDEX;
1926 phb_ctb[UPN].first_mtrcd = UNUSED_INDEX;
1927 phb_ctb[UPN].first_mnrcd = UNUSED_INDEX;
1928
1929 for (i=0; i<NR_EF_UPN; i++)
1930 {
1931 if (pcm_ReadRecord((UBYTE *)EF_UPN_ID,
1932 (USHORT)(i+1),
1933 SIZE_EF_UPN,
1934 (UBYTE *)&data[0],
1935 &version,
1936 &max_rcd) NEQ DRV_OK)
1937 {
1938 phb_ctb[UPN].mem = NO_PHB_ENTRY;
1939 phb_ctb[UPN].max_rcd = 0;
1940 }
1941 else
1942 {
1943 efupn = (EF_UPN *)&data[0];
1944 if (efupn->usrNum[0] NEQ 0xff)
1945 {
1946 /* search a free element in phonebook element table */
1947 if (pb_create_memory(&index) NEQ PHB_OK)
1948 return PHB_FULL;
1949
1950 phb_ctb[UPN].used_rcd++;
1951 n = (UBYTE)i/8;
1952 m = i%8;
1953 phb_ctb[UPN].rcd_bitmap[n] |= 0x01 << m;
1954
1955 phb_element[index].type = UPN;
1956 phb_element[index].entry.index = i+1;
1957
1958 /* copy record */
1959 memset(phb_element[index].entry.tag, 0xFF, sizeof(phb_element[index].entry.tag));
1960 memset(phb_element[index].entry.number, 0xFF, sizeof(phb_element[index].entry.number));
1961 memcpy(phb_element[index].entry.tag,
1962 efupn->alphId,
1963 10*sizeof(UBYTE));
1964 phb_element[index].entry.tag_len = pb_get_entry_len(efupn->alphId, 10);
1965 phb_element[index].entry.len = efupn->len;
1966 phb_element[index].entry.ton_npi = efupn->numTp;
1967 memcpy(phb_element[index].entry.number,
1968 efupn->usrNum,
1969 10*sizeof(UBYTE));
1970 phb_element[index].entry.cc_id = efupn->ccp;
1971
1972 pb_record_sort(index);
1973 pb_alpha_sort(index);
1974 pb_num_sort(index);
1975 }
1976 }
1977 }
1978 }
1979 phb_stat = PHB_READY;
1980 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, TRUE );
1981 read_flag = 1;
1982 return PHB_OK;
1983 }
1984
1985
1986 /*
1987 +--------------------------------------------------------------------+
1988 | PROJECT: MMI-Framework (8417) MODULE: PHB |
1989 | STATE : code ROUTINE: pb_read_sim_req |
1990 +--------------------------------------------------------------------+
1991
1992
1993 PURPOSE : Request to build phonebook.
1994
1995 */
1996
1997 void pb_read_sim_req(void)
1998 {
1999 UBYTE serv_stat;
2000
2001 TRACE_FUNCTION("pb_read_sim_req()");
2002
2003 /* Read Fixed Dialing Numbers from SIM card */
2004 if ((serv_stat = pb_ssc(SRV_FDN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2005 AND phb_ctb[FDN].mem EQ NO_PHB_ENTRY)
2006 {
2007 phb_ctb[FDN].mem = SIM_MEMORY;
2008 phb_ctb[FDN].type = FDN;
2009 phb_ctb[FDN].service = serv_stat;
2010 pb_read_sim(SIM_FDN, 1, NOT_PRESENT_8BIT);
2011 return;
2012 }
2013
2014 if (read_flag)
2015 {
2016 pb_read_eeprom_req();
2017 return;
2018 }
2019
2020 /* Read MSISDN from SIM card */
2021 if ((serv_stat = pb_ssc(SRV_MSISDN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2022 AND phb_ctb[UPN].mem EQ NO_PHB_ENTRY)
2023 {
2024 phb_ctb[UPN].mem = SIM_MEMORY;
2025 phb_ctb[UPN].type = UPN;
2026 phb_ctb[UPN].service = serv_stat;
2027 pb_read_sim(SIM_MSISDN, 1, NOT_PRESENT_8BIT);
2028 return;
2029 }
2030
2031 /* Read Barred Dialing Numbers from SIM card */
2032 if ((serv_stat = pb_ssc(SRV_BDN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2033 AND phb_ctb[BDN].mem EQ NO_PHB_ENTRY)
2034 {
2035 phb_ctb[BDN].mem = SIM_MEMORY;
2036 phb_ctb[BDN].type = BDN;
2037 phb_ctb[BDN].service = serv_stat;
2038 pb_read_sim(SIM_BDN, 1, NOT_PRESENT_8BIT);
2039 return;
2040 }
2041
2042 /* Read Service Dialing Numbers from SIM card */
2043 if ((serv_stat = pb_ssc(SRV_SDN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2044 AND phb_ctb[SDN].mem EQ NO_PHB_ENTRY)
2045 {
2046 phb_ctb[SDN].mem = SIM_MEMORY;
2047 phb_ctb[SDN].type = SDN;
2048 phb_ctb[SDN].service = serv_stat;
2049 pb_read_sim(SIM_SDN, 1, NOT_PRESENT_8BIT);
2050 return;
2051 }
2052
2053
2054 /* Read Last Numbers Dialed from SIM card */
2055 if ((serv_stat = pb_ssc(SRV_LDN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2056 AND phb_ctb[LDN].mem EQ NO_PHB_ENTRY)
2057 {
2058 phb_ctb[LDN].mem = TE_MEMORY;
2059 phb_ctb[LDN].type = LDN;
2060 phb_ctb[LDN].service = serv_stat;
2061 phb_ctb[LDN].max_rcd = MAX_RDM_RECORDS/3;
2062 phb_ctb[LDN].used_rcd = 0;
2063 phb_ctb[LDN].first_rcd = UNUSED_INDEX;
2064 phb_ctb[LDN].first_trcd = UNUSED_INDEX;
2065 phb_ctb[LDN].first_nrcd = UNUSED_INDEX;
2066 phb_ctb[LDN].first_mtrcd = UNUSED_INDEX;
2067 phb_ctb[LDN].first_mnrcd = UNUSED_INDEX;
2068 pb_read_sim(SIM_LND, 1, NOT_PRESENT_8BIT);
2069 return;
2070 }
2071
2072
2073 #ifdef PHONEBOOK_EXTENSION
2074 /* Read Ext1 Records from SIM card */
2075 if ((serv_stat = pb_ssc(SRV_EXT1,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2076 AND phb_ext_records[EXT1].mem EQ NO_PHB_ENTRY)
2077 {
2078 TRACE_EVENT ("Start reading EXT1");
2079 phb_ext_records[EXT1].mem = SIM_MEMORY;
2080 pb_read_sim(SIM_EXT1, 1, NOT_PRESENT_8BIT);
2081 return;
2082 }
2083
2084 /* Read Ext2 Records from SIM card */
2085 if ((serv_stat = pb_ssc(SRV_EXT2,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED
2086 AND phb_ext_records[EXT2].mem EQ NO_PHB_ENTRY)
2087 {
2088 TRACE_EVENT ("Start reading EXT2");
2089 phb_ext_records[EXT2].mem = SIM_MEMORY;
2090 pb_read_sim(SIM_EXT2, 1, NOT_PRESENT_8BIT);
2091 return;
2092 }
2093 #endif
2094
2095 /* Read phonebook from EEPROM */
2096 pb_read_eeprom_req();
2097
2098 #ifdef SIM_TOOLKIT
2099 if (simShrdPrm.fuRef >= 0)
2100 {
2101 psaSAT_FUConfirm (simShrdPrm.fuRef, SIM_FU_SUCC_ADD);
2102 }
2103 #endif
2104
2105 }
2106
2107 /*
2108 +--------------------------------------------------------------------+
2109 | PROJECT: MMI-Framework (8417) MODULE: PHB |
2110 | STATE : code ROUTINE: pb_build_req |
2111 +--------------------------------------------------------------------+
2112
2113 PURPOSE : Request to build phonebook.
2114
2115 */
2116
2117 void pb_build_req(T_SIM_MMI_INSERT_IND *sim_mmi_insert_ind)
2118 {
2119 UBYTE simIMSI[MAX_IMSI_LEN+1];
2120 UBYTE pcmIMSI[MAX_IMSI_LEN+1];
2121 EF_IMSI imsi;
2122 UBYTE version;
2123
2124 #ifndef _SIMULATION_
2125 UBYTE classFDN = (UBYTE) CLASS_None;
2126 T_FFS_RET ret_ffs; /* FFS handle */
2127 #endif
2128
2129 TRACE_FUNCTION ("pb_build_req()");
2130
2131 if (fdn_mode EQ NO_OPERATION)
2132 {
2133 /* Read SIM service table from SIM card */
2134 memcpy(sim_service_table, sim_mmi_insert_ind -> sim_serv, MAX_SRV_TBL);
2135
2136 /* Compare IMSI field between SIM and PCM */
2137 imsiFlag = FALSE;
2138 psaSIM_decodeIMSI (sim_mmi_insert_ind->imsi_field.field,
2139 sim_mmi_insert_ind->imsi_field.c_field,
2140 (char *)simIMSI);
2141
2142 if (pcm_ReadFile((UBYTE *) EF_IMSI_ID,SIZE_EF_IMSI,
2143 (UBYTE *) &imsi, &version) EQ PCM_OK)
2144 {
2145 psaSIM_decodeIMSI (imsi.IMSI, imsi.len, (char *)pcmIMSI);
2146 if (!strcmp((char *)simIMSI, (char *)pcmIMSI))
2147 imsiFlag = TRUE;
2148 else
2149 {
2150 /* write the IMSI in PCM */
2151 imsi.len = sim_mmi_insert_ind->imsi_field.c_field;
2152 memcpy(imsi.IMSI, sim_mmi_insert_ind->imsi_field.field, MAX_IMSI-1);
2153 pcm_WriteFile((UBYTE *) EF_IMSI_ID,SIZE_EF_IMSI,
2154 (UBYTE *) &imsi);
2155 }
2156 }
2157
2158 switch (sim_mmi_insert_ind -> func)
2159 {
2160 case SIM_ADN_ENABLED:
2161 case SIM_ADN_BDN_ENABLED:
2162 fdn_mode = FDN_DISABLE;
2163 break;
2164 case SIM_FDN_ENABLED:
2165 case SIM_FDN_BDN_ENABLED:
2166 fdn_mode = FDN_ENABLE;
2167 #ifndef _SIMULATION_
2168 /* read last fdn_classtype from FFS */
2169 ret_ffs = ffs_fread("/mmi/fdnClassType",
2170 &classFDN,
2171 sizeof(classFDN));
2172
2173 if(!(ret_ffs < 1)) /* successful read */
2174 {
2175 /* only these two classes are currently supported */
2176 if ( classFDN EQ (UBYTE) CLASS_VceDatFax OR
2177 classFDN EQ (UBYTE) CLASS_VceDatFaxSms )
2178 {
2179 fdn_classtype = classFDN;
2180 fdn_input_classtype = fdn_classtype;
2181 }
2182 }
2183 #endif
2184 break;
2185 default:
2186 fdn_mode = NO_OPERATION;
2187 break;
2188 }
2189 }
2190 }
2191
2192 /*
2193 +--------------------------------------------------------------------+
2194 | PROJECT: MMI-Framework (8417) MODULE: PHB |
2195 | STATE : code ROUTINE: pb_start_build |
2196 +--------------------------------------------------------------------+
2197
2198 PURPOSE : Start reading the phonebook.
2199
2200 */
2201
2202 T_PHB_RETURN pb_start_build (BOOL unchanged)
2203 {
2204 UBYTE serv_stat;
2205
2206 TRACE_FUNCTION ("pb_start_build()");
2207
2208 read_flag = 0;
2209 phb_stat = PHB_BUSY;
2210 cmhPHB_StatIndication ( PHB_BUSY, CME_ERR_NotPresent, TRUE );
2211
2212 /* Read Abbreviated Dialing Numbers */
2213 if ((serv_stat = pb_ssc(SRV_ADN,sim_service_table)) EQ ALLOCATED_AND_ACTIVATED)
2214 {
2215 if (fdn_mode EQ FDN_ENABLE)
2216 {
2217 pb_read_sim_req();
2218 return PHB_OK;
2219 }
2220
2221 if ( phb_ctb[ADN].mem EQ NO_PHB_ENTRY )
2222 {
2223 phb_ctb[ADN].mem = SIM_MEMORY;
2224 phb_ctb[ADN].type = ADN;
2225 phb_ctb[ADN].service = serv_stat;
2226
2227 pb_read_sim(SIM_ADN, 1, NOT_PRESENT_8BIT);
2228 }
2229 else
2230 pb_read_sim_req();
2231 }
2232
2233 else
2234 {
2235 pb_read_sim_req();
2236 }
2237 return PHB_OK;
2238 }
2239
2240 /*
2241 +--------------------------------------------------------------------+
2242 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2243 | STATE : code ROUTINE : pb_update |
2244 +--------------------------------------------------------------------+
2245
2246 PURPOSE : Phonebook update on File Change Notification.
2247
2248 */
2249
2250 #ifdef SIM_TOOLKIT
2251 BOOL pb_update (int ref, T_SIM_FILE_UPDATE_IND *fu)
2252 {
2253 BOOL found = FALSE;
2254 int i;
2255
2256 TRACE_FUNCTION ("pb_update ()");
2257
2258 for (i = 0; i < (int)fu->val_nr; i++)
2259 {
2260 if (fu->file_id[i] EQ SIM_ADN OR /* the extension datafields */
2261 fu->file_id[i] EQ SIM_FDN OR /* have to be added, when*/
2262 fu->file_id[i] EQ SIM_BDN OR /* they are really used */
2263 fu->file_id[i] EQ SIM_SDN OR
2264 fu->file_id[i] EQ SIM_MSISDN OR
2265 fu->file_id[i] EQ SIM_SST OR
2266 fu->file_id[i] EQ SIM_LND) /*CQ16301: Added support for LND refresh */
2267 {
2268 found = TRUE;
2269
2270 /* when SIM service table is changed, the all SIM-phonebooks
2271 will be updated. */
2272 if (fu->file_id[i] EQ SIM_SST)
2273 {
2274 sstUpdateId = TRUE;
2275 break;
2276 }
2277
2278 pb_sat_update_reset(fu->file_id[i]);
2279 }
2280 }
2281
2282 if (found)
2283 {
2284 simShrdPrm.fuRef = ref;
2285 if (sstUpdateId)
2286 {
2287 sstUpdateId = FALSE;
2288
2289 /* Update SIM service table */
2290 if (pb_read_sim_dat(SIM_SST, NOT_PRESENT_8BIT, (UBYTE)256) EQ FALSE )
2291 pb_start_build (FALSE);
2292 }
2293 else
2294 pb_start_build (FALSE);
2295 return FALSE;
2296 }
2297 else
2298 {
2299 simShrdPrm.fuRef = -1; /* no update needed */
2300 return TRUE;
2301 }
2302 }
2303 #endif
2304
2305 /*
2306 +--------------------------------------------------------------------+
2307 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2308 | STATE : code ROUTINE : pb_ssc |
2309 +--------------------------------------------------------------------+
2310
2311 PURPOSE : Check SIM service status.
2312
2313 */
2314
2315 UBYTE pb_ssc (UBYTE nr, UBYTE * serv_table)
2316 {
2317 TRACE_FUNCTION ("pb_ssc()");
2318
2319 if (nr > MAX_SRV_TBL*4)
2320 {
2321 TRACE_ERROR ("serv_table overflow in pb_ssc()");
2322 return NO_ALLOCATED;
2323 }
2324
2325 /* SDN and BDN are not used */
2326 /* if ((nr EQ 18) || (nr EQ31)) */
2327 /* return(NO_ALLOCATED);*/
2328
2329 return ( *(serv_table+(nr-1)/4) >> (((nr-1)&3)*2) & 0x03);
2330 }
2331
2332
2333 /*
2334 +---------------------------------------------------------------------+
2335 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2336 | STATE : code ROUTINE : pb_record_sort |
2337 +---------------------------------------------------------------------+
2338
2339 PURPOSE :
2340
2341 */
2342
2343 void pb_record_sort(SHORT cur_index)
2344 {
2345 SHORT ref_index;
2346 SHORT ptr_index;
2347 UBYTE flag;
2348
2349 /* TRACE_FUNCTION ("pb_record_sort()"); */
2350
2351 if (phb_ctb[phb_element[cur_index].type].used_rcd EQ 1)
2352 {
2353 phb_element[cur_index].prev_rcd = UNUSED_INDEX;
2354 phb_element[cur_index].next_rcd = UNUSED_INDEX;
2355 phb_ctb[phb_element[cur_index].type].first_rcd = cur_index;
2356 }
2357 else
2358 {
2359 flag = 0;
2360
2361 ref_index = phb_ctb[phb_element[cur_index].type].first_rcd;
2362 phb_ctb[phb_element[cur_index].type].first_rcd = cur_index;
2363
2364 phb_element[cur_index].prev_rcd = UNUSED_INDEX;
2365 phb_element[cur_index].next_rcd = ref_index;
2366 phb_element[ref_index].prev_rcd = cur_index;
2367
2368 while (ref_index NEQ UNUSED_INDEX)
2369 {
2370 if (phb_element[cur_index].entry.index > phb_element[ref_index].entry.index)
2371 {
2372 ptr_index = phb_element[ref_index].next_rcd;
2373 if (ptr_index != UNUSED_INDEX)
2374 phb_element[ptr_index].prev_rcd = cur_index;
2375 phb_element[cur_index].next_rcd = ptr_index;
2376
2377 ptr_index = phb_element[cur_index].prev_rcd;
2378 if (ptr_index != UNUSED_INDEX)
2379 phb_element[ptr_index].next_rcd = ref_index;
2380
2381 phb_element[ref_index].prev_rcd = phb_element[cur_index].prev_rcd;
2382 phb_element[ref_index].next_rcd = cur_index;
2383 phb_element[cur_index].prev_rcd = ref_index;
2384
2385 /* set the first record in control block */
2386 if(!flag)
2387 {
2388 phb_ctb[phb_element[cur_index].type].first_rcd = ref_index;
2389 flag = 1;
2390 }
2391 ref_index = phb_element[cur_index].next_rcd;
2392 }
2393
2394 else
2395 ref_index = phb_element[ref_index].next_rcd;
2396 }
2397 }
2398 }
2399
2400
2401 /*
2402 +---------------------------------------------------------------------+
2403 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2404 | STATE : code ROUTINE : pb_l_record_sort |
2405 +---------------------------------------------------------------------+
2406
2407 PURPOSE :
2408
2409 */
2410
2411 void pb_l_record_sort(SHORT cur_index)
2412 {
2413 SHORT ref_index;
2414 SHORT ptr_index;
2415 UBYTE flag;
2416
2417 TRACE_FUNCTION ("pb_l_record_sort()");
2418
2419 if (phb_ctb[phb_l_element[cur_index].type].used_rcd EQ 1)
2420 {
2421 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
2422 phb_l_element[cur_index].next_rcd = UNUSED_BYTE_INDEX;
2423 phb_ctb[phb_l_element[cur_index].type].first_rcd = cur_index;
2424 }
2425 else
2426 {
2427 flag = 0;
2428
2429 ref_index = phb_ctb[phb_l_element[cur_index].type].first_rcd;
2430 phb_ctb[phb_l_element[cur_index].type].first_rcd = cur_index;
2431
2432 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
2433 phb_l_element[cur_index].next_rcd = (UBYTE)ref_index;
2434 phb_l_element[ref_index].prev_rcd = (UBYTE)cur_index;
2435
2436 while ((UBYTE)ref_index NEQ UNUSED_BYTE_INDEX)
2437 {
2438 if (phb_l_element[cur_index].entry.index > phb_l_element[ref_index].entry.index)
2439 {
2440 ptr_index = (SHORT)phb_l_element[ref_index].next_rcd;
2441 if ((UBYTE)ptr_index != UNUSED_BYTE_INDEX)
2442 phb_l_element[ptr_index].prev_rcd = (UBYTE)cur_index;
2443 phb_l_element[cur_index].next_rcd = (UBYTE)ptr_index;
2444
2445 ptr_index = (SHORT)phb_l_element[cur_index].prev_rcd;
2446 if ((UBYTE)ptr_index != UNUSED_BYTE_INDEX)
2447 phb_l_element[ptr_index].next_rcd = (UBYTE)ref_index;
2448
2449 phb_l_element[ref_index].prev_rcd = phb_l_element[cur_index].prev_rcd;
2450 phb_l_element[ref_index].next_rcd = (UBYTE)cur_index;
2451 phb_l_element[cur_index].prev_rcd = (UBYTE)ref_index;
2452
2453 /* set the first record in control block */
2454 if(!flag)
2455 {
2456 phb_ctb[phb_l_element[cur_index].type].first_rcd = ref_index;
2457 flag = 1;
2458 }
2459 ref_index = (SHORT)phb_l_element[cur_index].next_rcd;
2460 }
2461
2462 else
2463 ref_index = (SHORT)phb_l_element[ref_index].next_rcd;
2464 }
2465 }
2466 }
2467
2468
2469 /*
2470 +---------------------------------------------------------------------+
2471 | PROJECT : MMI-Framework (8417) MODULE : PHB |
2472 | STATE : code ROUTINE : pb_cvt_alpha_for_cmp |
2473 +---------------------------------------------------------------------+
2474
2475 PURPOSE : convert alpha to lower case when not unicode
2476
2477 */
2478 static void pb_cvt_alpha_for_cmp ( UBYTE *src,
2479 UBYTE *dst,
2480 UBYTE len )
2481 {
2482 int i;
2483
2484 if ( *src NEQ 0x80 )
2485 {
2486 for ( i = 0; i < len; i++ )
2487 dst[i] = (UBYTE)tolower((int)src[i]);
2488
2489 return;
2490 }
2491
2492 for ( i = 0; i < len; i++ )
2493 dst[i] = src[i];
2494 }
2495
2496 /*
2497 +---------------------------------------------------------------------+
2498 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2499 | STATE : code ROUTINE : pb_alpha_sort |
2500 +---------------------------------------------------------------------+
2501
2502 PURPOSE : Insert a new record to alpha sorted chain.
2503
2504 */
2505
2506 void pb_alpha_sort(SHORT cur_index)
2507 {
2508 SHORT ref_index;
2509 SHORT ptr_index;
2510 UBYTE flag, cmpLen = 0;
2511 UBYTE cur_tag[PHB_MAX_TAG_LEN], check_tag[PHB_MAX_TAG_LEN];
2512 int cmp_res;
2513
2514 /* set the new record as first element */
2515 if (phb_ctb[phb_element[cur_index].type].used_rcd EQ 1)
2516 {
2517 phb_element[cur_index].prev_trcd = UNUSED_INDEX;
2518 phb_element[cur_index].next_trcd = UNUSED_INDEX;
2519
2520 phb_ctb[phb_element[cur_index].type].first_trcd = cur_index;
2521 }
2522
2523 if (phb_ctb[phb_element[cur_index].type].used_rcd > 1)
2524 {
2525 ref_index = phb_ctb[phb_element[cur_index].type].first_trcd;
2526 phb_ctb[phb_element[cur_index].type].first_trcd = cur_index;
2527
2528 phb_element[cur_index].prev_trcd = UNUSED_INDEX;
2529 phb_element[cur_index].next_trcd = ref_index;
2530 phb_element[ref_index].prev_trcd = cur_index;
2531
2532 /* insert the new record in the alpha order */
2533 flag = 0;
2534 while (ref_index NEQ UNUSED_INDEX)
2535 {
2536 memset(cur_tag, 0, sizeof ( cur_tag ) );
2537 memset(check_tag, 0, sizeof ( check_tag ) );
2538
2539 /*
2540 this should not cause problems, because in both alphabets
2541 (GSM and ASCII) the most important chars are at the same
2542 positions (A-Z: 65-90 a-z:97-122)
2543 */
2544
2545 if( ext_compare_fct != NULL )
2546 {
2547 cmp_res = ext_compare_fct ( phb_element[cur_index].entry.tag,
2548 phb_element[cur_index].entry.tag_len,
2549 phb_element[ref_index].entry.tag,
2550 phb_element[ref_index].entry.tag_len );
2551 }
2552 else
2553 {
2554 pb_cvt_alpha_for_cmp ( phb_element[cur_index].entry.tag,
2555 cur_tag,
2556 phb_element[cur_index].entry.tag_len );
2557 pb_cvt_alpha_for_cmp ( phb_element[ref_index].entry.tag,
2558 check_tag,
2559 phb_element[ref_index].entry.tag_len );
2560 cmpLen = MINIMUM ( phb_element[cur_index].entry.tag_len,
2561 phb_element[ref_index].entry.tag_len );
2562
2563 cmp_res = cmpString ( cur_tag, check_tag, cmpLen );
2564 }
2565
2566 if (cmp_res EQ 0) /* MINIMUM character match, so check if one string is longer */
2567 { /* ABC should come after AB */
2568 if (phb_element[cur_index].entry.tag_len NEQ phb_element[ref_index].entry.tag_len)
2569 {
2570 if ((phb_element[cur_index].entry.tag_len - phb_element[ref_index].entry.tag_len) > 0)
2571 cmp_res = cmpLen + 1;
2572 else
2573 cmp_res = -cmpLen - 1;
2574 }
2575 }
2576
2577 if(cmp_res > 0)
2578 {
2579 ptr_index = phb_element[ref_index].next_trcd;
2580 if (ptr_index != UNUSED_INDEX)
2581 {
2582 phb_element[ptr_index].prev_trcd = cur_index;
2583 }
2584 phb_element[cur_index].next_trcd = ptr_index;
2585
2586 ptr_index = phb_element[cur_index].prev_trcd;
2587 if (ptr_index != UNUSED_INDEX)
2588 {
2589 phb_element[ptr_index].next_trcd = ref_index;
2590 }
2591
2592 phb_element[ref_index].prev_trcd = phb_element[cur_index].prev_trcd;
2593 phb_element[ref_index].next_trcd = cur_index;
2594 phb_element[cur_index].prev_trcd = ref_index;
2595
2596 /* set the first record in control block */
2597 if(!flag)
2598 {
2599 phb_ctb[phb_element[cur_index].type].first_trcd = ref_index;
2600 flag = 1;
2601 }
2602 ref_index = phb_element[cur_index].next_trcd;
2603 }
2604 else
2605 {
2606 ref_index = phb_element[ref_index].next_trcd;
2607 }
2608 }
2609 }
2610 }
2611
2612
2613 /*
2614 +---------------------------------------------------------------------+
2615 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2616 | STATE : code ROUTINE : pb_num_sort |
2617 +---------------------------------------------------------------------+
2618
2619 PURPOSE :
2620
2621 */
2622
2623 void pb_num_sort(SHORT cur_index)
2624 {
2625 SHORT ref_index;
2626 SHORT ptr_index;
2627 UBYTE flag;
2628 CHAR cur_number[MAX_PHB_NUM_LEN];
2629 CHAR ref_number[MAX_PHB_NUM_LEN];
2630
2631 /* TRACE_FUNCTION ("pb_num_sort()");*/
2632
2633 /* set the new record as first element */
2634 if (phb_ctb[phb_element[cur_index].type].used_rcd EQ 1)
2635 {
2636 phb_element[cur_index].prev_nrcd = UNUSED_INDEX;
2637 phb_element[cur_index].next_nrcd = UNUSED_INDEX;
2638
2639 phb_ctb[phb_element[cur_index].type].first_nrcd = cur_index;
2640 }
2641
2642 if (phb_ctb[phb_element[cur_index].type].used_rcd > 1)
2643 {
2644 ref_index = phb_ctb[phb_element[cur_index].type].first_nrcd;
2645 phb_ctb[phb_element[cur_index].type].first_nrcd = cur_index;
2646
2647 phb_element[cur_index].prev_nrcd = UNUSED_INDEX;
2648 phb_element[cur_index].next_nrcd = ref_index;
2649 phb_element[ref_index].prev_nrcd = cur_index;
2650
2651 /* insert the new record in the number order */
2652 flag = 0;
2653 while (ref_index NEQ UNUSED_INDEX)
2654 {
2655 /* convert the number in BCD to string */
2656 cmhPHB_getAdrStr(cur_number,
2657 MAX_PHB_NUM_LEN - 1,
2658 phb_element[cur_index].entry.number,
2659 phb_element[cur_index].entry.len);
2660 cmhPHB_getAdrStr(ref_number,
2661 MAX_PHB_NUM_LEN - 1,
2662 phb_element[ref_index].entry.number,
2663 phb_element[ref_index].entry.len);
2664
2665 if (strcmp((char *)cur_number, (char *)ref_number) > 0)
2666 {
2667 ptr_index = phb_element[ref_index].next_nrcd;
2668 if (ptr_index != UNUSED_INDEX)
2669 phb_element[ptr_index].prev_nrcd = cur_index;
2670 phb_element[cur_index].next_nrcd = ptr_index;
2671
2672 ptr_index = phb_element[cur_index].prev_nrcd;
2673 if (ptr_index != UNUSED_INDEX)
2674 phb_element[ptr_index].next_nrcd = ref_index;
2675
2676 phb_element[ref_index].prev_nrcd = phb_element[cur_index].prev_nrcd;
2677 phb_element[ref_index].next_nrcd = cur_index;
2678 phb_element[cur_index].prev_nrcd = ref_index;
2679
2680 /* set the first logic number record in control block */
2681 if(!flag)
2682 {
2683 phb_ctb[phb_element[cur_index].type].first_nrcd = ref_index;
2684 flag = 1;
2685 }
2686 ref_index = phb_element[cur_index].next_nrcd;
2687 }
2688 else
2689 {
2690 ref_index = phb_element[ref_index].next_nrcd;
2691 }
2692 }
2693 }
2694 }
2695
2696
2697 /*
2698 +---------------------------------------------------------------------+
2699 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2700 | STATE : code ROUTINE : pb_malpha_sort |
2701 +---------------------------------------------------------------------+
2702
2703 PURPOSE : Insert a new record to alpha sorted chain.
2704
2705 */
2706
2707 void pb_malpha_sort(SHORT cur_index)
2708 {
2709 SHORT ref_index;
2710 SHORT ptr_index;
2711 UBYTE flag, cmpLen = 0;
2712 UBYTE cur_tag[PHB_MAX_TAG_LEN], check_tag[PHB_MAX_TAG_LEN];
2713 int cmp_res;
2714
2715 if (((phb_ctb[ADN].used_rcd EQ 1) AND (phb_ctb[FDN].used_rcd EQ 0))
2716 OR ((phb_ctb[ADN].used_rcd EQ 0) AND (phb_ctb[FDN].used_rcd EQ 1)))
2717 {
2718 phb_element[cur_index].prev_mtrcd = UNUSED_INDEX;
2719 phb_element[cur_index].next_mtrcd = UNUSED_INDEX;
2720
2721 phb_ctb[phb_element[cur_index].type].first_mtrcd = cur_index;
2722 return;
2723 }
2724 else
2725 {
2726 if (phb_ctb[ADN].used_rcd NEQ 0)
2727 {
2728 /* Test whether ADN's first_mtrcd index is already in use or not.
2729 If not and FDN entries exist, take FDN's first_mtrcd. */
2730 if ((phb_ctb[ADN].first_mtrcd EQ UNUSED_INDEX) AND (phb_ctb[FDN].used_rcd NEQ 0))
2731 ref_index = phb_ctb[FDN].first_mtrcd;
2732 else
2733 ref_index = phb_ctb[ADN].first_mtrcd;
2734
2735 phb_ctb[ADN].first_mtrcd = cur_index;
2736 }
2737 else
2738 {
2739 ref_index = phb_ctb[FDN].first_mtrcd;
2740 phb_ctb[FDN].first_mtrcd = cur_index;
2741 }
2742 }
2743
2744 phb_element[cur_index].prev_mtrcd = UNUSED_INDEX;
2745 phb_element[cur_index].next_mtrcd = ref_index;
2746 phb_element[ref_index].prev_mtrcd = cur_index;
2747
2748 /* insert the new record in the alpha order */
2749 flag = 0;
2750 while (ref_index NEQ UNUSED_INDEX)
2751 {
2752 memset(cur_tag, 0, sizeof ( cur_tag ) );
2753 memset(check_tag, 0, sizeof ( check_tag ) );
2754
2755 /*
2756 this should not cause problems, because in both alphabets
2757 (GSM and ASCII) the most important chars are at the same
2758 positions (A-Z: 65-90 a-z:97-122)
2759 */
2760 if( ext_compare_fct != NULL )
2761 {
2762 cmp_res = ext_compare_fct ( phb_element[cur_index].entry.tag,
2763 phb_element[cur_index].entry.tag_len,
2764 phb_element[ref_index].entry.tag,
2765 phb_element[ref_index].entry.tag_len );
2766 }
2767 else
2768 {
2769 pb_cvt_alpha_for_cmp ( phb_element[cur_index].entry.tag,
2770 cur_tag,
2771 phb_element[cur_index].entry.tag_len );
2772 pb_cvt_alpha_for_cmp ( phb_element[ref_index].entry.tag,
2773 check_tag,
2774 phb_element[ref_index].entry.tag_len );
2775 cmpLen = MINIMUM ( phb_element[cur_index].entry.tag_len,
2776 phb_element[ref_index].entry.tag_len );
2777
2778 cmp_res = cmpString ( cur_tag, check_tag, cmpLen );
2779 }
2780
2781 if (cmp_res EQ 0) /* MINIMUM character match, so check if one string is longer */
2782 { /* ABC should come after AB */
2783 if (phb_element[cur_index].entry.tag_len NEQ phb_element[ref_index].entry.tag_len)
2784 {
2785 if ((phb_element[cur_index].entry.tag_len - phb_element[ref_index].entry.tag_len) > 0)
2786 cmp_res = cmpLen + 1;
2787 else
2788 cmp_res = -cmpLen - 1;
2789 }
2790 }
2791
2792 if (cmp_res > 0)
2793 {
2794 ptr_index = phb_element[ref_index].next_mtrcd;
2795 if (ptr_index != UNUSED_INDEX)
2796 phb_element[ptr_index].prev_mtrcd = cur_index;
2797 phb_element[cur_index].next_mtrcd = ptr_index;
2798
2799 ptr_index = phb_element[cur_index].prev_mtrcd;
2800 if (ptr_index != UNUSED_INDEX)
2801 phb_element[ptr_index].next_mtrcd = ref_index;
2802
2803 phb_element[ref_index].prev_mtrcd = phb_element[cur_index].prev_mtrcd;
2804 phb_element[ref_index].next_mtrcd = cur_index;
2805 phb_element[cur_index].prev_mtrcd = ref_index;
2806
2807 /* set the first record in control block */
2808 if(!flag)
2809 {
2810 if (phb_ctb[ADN].used_rcd != 0)
2811 phb_ctb[ADN].first_mtrcd = ref_index;
2812 else
2813 phb_ctb[FDN].first_mtrcd = ref_index;
2814
2815 flag = 1;
2816 }
2817 ref_index = phb_element[cur_index].next_mtrcd;
2818 }
2819 else
2820 ref_index = phb_element[ref_index].next_mtrcd;
2821 }
2822 }
2823
2824
2825 /*
2826 +---------------------------------------------------------------------+
2827 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2828 | STATE : code ROUTINE : pb_mnum_sort |
2829 +---------------------------------------------------------------------+
2830
2831 PURPOSE :
2832
2833 */
2834
2835 void pb_mnum_sort(SHORT cur_index)
2836 {
2837 SHORT ref_index;
2838 SHORT ptr_index;
2839 UBYTE flag;
2840 CHAR cur_number[MAX_PHB_NUM_LEN];
2841 CHAR ref_number[MAX_PHB_NUM_LEN];
2842
2843 /* TRACE_FUNCTION ("pb_num_sort()");*/
2844
2845 if (((phb_ctb[ADN].used_rcd EQ 1) AND (phb_ctb[FDN].used_rcd EQ 0))
2846 OR ((phb_ctb[ADN].used_rcd EQ 0) AND (phb_ctb[FDN].used_rcd EQ 1)))
2847 {
2848 phb_element[cur_index].prev_mnrcd = UNUSED_INDEX;
2849 phb_element[cur_index].next_mnrcd = UNUSED_INDEX;
2850
2851 phb_ctb[phb_element[cur_index].type].first_mnrcd = cur_index;
2852 return;
2853 }
2854 else
2855 {
2856 if (phb_ctb[ADN].used_rcd != 0)
2857 {
2858 /* Test whether ADN's first_mtrcd index is already in use or not.
2859 If not and FDN entries exist, take FDN's first_mtrcd. */
2860 if ((phb_ctb[ADN].first_mnrcd EQ UNUSED_INDEX) AND (phb_ctb[FDN].used_rcd NEQ 0))
2861 ref_index = phb_ctb[FDN].first_mnrcd;
2862 else
2863 ref_index = phb_ctb[ADN].first_mnrcd;
2864
2865 phb_ctb[ADN].first_mnrcd = cur_index;
2866 }
2867 else
2868 {
2869 ref_index = phb_ctb[FDN].first_mnrcd;
2870 phb_ctb[FDN].first_mnrcd = cur_index;
2871 }
2872 }
2873
2874 phb_element[cur_index].prev_mnrcd = UNUSED_INDEX;
2875 phb_element[cur_index].next_mnrcd = ref_index;
2876 phb_element[ref_index].prev_mnrcd = cur_index;
2877
2878 /* insert the new record in the number order */
2879 flag = 0;
2880 while (ref_index NEQ UNUSED_INDEX)
2881 {
2882 /* convert the number in BCD to string */
2883 cmhPHB_getAdrStr(cur_number,
2884 MAX_PHB_NUM_LEN - 1,
2885 phb_element[cur_index].entry.number,
2886 phb_element[cur_index].entry.len);
2887 cmhPHB_getAdrStr(ref_number,
2888 MAX_PHB_NUM_LEN - 1,
2889 phb_element[ref_index].entry.number,
2890 phb_element[ref_index].entry.len);
2891
2892 if (strcmp((char *)cur_number, (char *)ref_number) > 0)
2893 {
2894 ptr_index = phb_element[ref_index].next_mnrcd;
2895 if (ptr_index != UNUSED_INDEX)
2896 phb_element[ptr_index].prev_mnrcd = cur_index;
2897 phb_element[cur_index].next_mnrcd = ptr_index;
2898
2899 ptr_index = phb_element[cur_index].prev_mnrcd;
2900 if (ptr_index != UNUSED_INDEX)
2901 phb_element[ptr_index].next_mnrcd = ref_index;
2902
2903 phb_element[ref_index].prev_mnrcd = phb_element[cur_index].prev_mnrcd;
2904 phb_element[ref_index].next_mnrcd = cur_index;
2905 phb_element[cur_index].prev_mnrcd = ref_index;
2906
2907 /* set the first logic number record in control block */
2908 if(!flag)
2909 {
2910 if (phb_ctb[ADN].used_rcd != 0)
2911 phb_ctb[ADN].first_mnrcd = ref_index;
2912 else
2913 phb_ctb[FDN].first_mnrcd = ref_index;
2914 flag = 1;
2915 }
2916 ref_index = phb_element[cur_index].next_mnrcd;
2917 }
2918 else
2919 ref_index = phb_element[ref_index].next_mnrcd;
2920 }
2921 }
2922
2923
2924 /*
2925 +---------------------------------------------------------------------+
2926 | PROJECT : MMI-Framework (8417) MODULE: PHB |
2927 | STATE : code ROUTINE : pb_add_record |
2928 +---------------------------------------------------------------------+
2929
2930 PURPOSE :
2931
2932 */
2933
2934 T_PHB_RETURN pb_add_record(UBYTE type, UBYTE index, T_PHB_RECORD *entry)
2935 {
2936 UBYTE bit = 0;
2937 UBYTE tag_len;
2938 SHORT new_index;
2939 SHORT cur_index;
2940 SHORT first_id;
2941 SHORT result;
2942 T_PHB_RECORD found_entry;
2943 UBYTE n,m;
2944 UBYTE pos;
2945 UBYTE i;
2946 UBYTE number[MAX_PHB_NUM_LEN];
2947 T_PHB_RETURN sim_result;
2948 UBYTE old_ext_rcd_num = 0xFF;
2949 int entrylen;
2950 #ifdef PHONEBOOK_EXTENSION
2951 USHORT file_id = 0;
2952 #endif
2953
2954 TRACE_FUNCTION ("pb_add_record()");
2955
2956 /* check whether this phonebook exists */
2957 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
2958 return PHB_FAIL;
2959
2960 if (type EQ ECC
2961 OR type EQ ADN
2962 OR type EQ FDN
2963 OR type EQ BDN
2964 OR type EQ UPN)
2965 {
2966 /* Phonebook is full. */
2967 if (phb_ctb[type].used_rcd >= phb_ctb[type].max_rcd AND !index)
2968 {
2969 return PHB_FULL;
2970 }
2971
2972 tag_len = pb_get_entry_len( entry->tag, PHB_MAX_TAG_LEN );
2973 /* tag_len = MINIMUM ( tag_len, phb_ctb[type].alpha_len); */
2974 /* Don't truncate a tag if it does not fit onto SIM but raise an error */
2975 if (tag_len > phb_ctb[type].alpha_len)
2976 {
2977 return PHB_TAG_EXCEEDED;
2978 }
2979
2980 /* Search the free record number for this record */
2981 if (!index)
2982 {
2983 T_PHB_RETURN ret;
2984 SHORT first_free;
2985
2986 switch (type)
2987 {
2988 case ADN:
2989 case FDN:
2990 case BDN:
2991 case UPN:
2992 /*
2993 * Use the function pb_first_free() to determine
2994 * the index of the first free record.
2995 */
2996 ret=pb_first_free(type,&first_free);
2997
2998 /*
2999 * Get out if there was a problem, or the phonebook
3000 * is full.
3001 */
3002 if (ret NEQ PHB_OK)
3003 return(ret);
3004
3005 bit=(UBYTE)(first_free-1);
3006 break;
3007
3008 default:
3009 bit=0;
3010 }
3011 }
3012
3013 /* Delete the information in the record, in order to overwrite */
3014 if (index)
3015 {
3016 bit = index - 1;
3017 pb_delete_record(type, index, &old_ext_rcd_num, FALSE);
3018 }
3019
3020 /* search a free element in phonebook element table */
3021 if (pb_create_memory(&new_index) NEQ PHB_OK)
3022 return PHB_FULL;
3023 phb_element[new_index].type = type;
3024 #ifdef PHONEBOOK_EXTENSION
3025 phb_element[new_index].entry.ext_rcd_num = 0xFF;
3026 #endif
3027 phb_ctb[type].used_rcd++;
3028
3029 if (type EQ ADN OR type EQ FDN)
3030 phb_ctb[ADN_FDN].used_rcd++;
3031 n = (UBYTE)bit/8;
3032 m = bit%8;
3033 phb_ctb[type].rcd_bitmap[n] |= 0x01 << m;
3034 phb_element[new_index].entry.index = bit + 1;
3035
3036 /* Copy entry */
3037 phb_element[new_index].entry.tag_len = tag_len;
3038 phb_element[new_index].entry.len = entry->len;
3039 phb_element[new_index].entry.ton_npi = entry->ton_npi;
3040 memset(phb_element[new_index].entry.tag, 0xFF, PHB_MAX_TAG_LEN);
3041 memcpy((char *)phb_element[new_index].entry.tag,
3042 (char *)entry->tag,
3043 tag_len);
3044 memcpy((char *)phb_element[new_index].entry.number,
3045 (char *)entry->number,
3046 PHB_PACKED_NUM_LEN); /* allow number (10 bytes) + a extension (11 bytes) */
3047 #ifdef PHONEBOOK_EXTENSION
3048 memcpy((char *)phb_element[new_index].entry.subaddr,
3049 (char *)entry->subaddr, PHB_PACKED_NUM_LEN);
3050 #endif
3051 phb_element[new_index].entry.cc_id = entry->cc_id;
3052
3053 pb_record_sort(new_index);
3054 pb_alpha_sort(new_index);
3055 pb_num_sort(new_index);
3056
3057 if ((type EQ ADN) OR (type EQ FDN))
3058 {
3059 pb_malpha_sort(new_index);
3060 pb_mnum_sort(new_index);
3061 }
3062
3063 if (phb_ctb[type].mem EQ SIM_MEMORY)
3064 {
3065 /* write this record in SIM card */
3066 memset(data, 0xFF, sizeof(data));
3067 memcpy(data, entry->tag, tag_len);
3068
3069 #if PHONEBOOK_EXTENSION
3070 if (entry->number[10] != 0xFF)
3071 {
3072 data[phb_ctb[type].alpha_len] = 11; /* max. length */
3073 }
3074 else
3075 {
3076 data[phb_ctb[type].alpha_len] = entry->len+1;
3077 }
3078 #else
3079 data[phb_ctb[type].alpha_len] = entry->len+1;
3080 #endif
3081 data[phb_ctb[type].alpha_len+1] = entry->ton_npi;
3082 memcpy((char *)&data[phb_ctb[type].alpha_len+2],
3083 (char *)entry->number, 10);
3084 data[phb_ctb[type].alpha_len+12] = entry->cc_id;
3085
3086 #ifdef PHONEBOOK_EXTENSION
3087 if (entry->number[10] != 0xFF)
3088 {
3089 file_id = pb_get_ext_file_id (type);
3090 if (old_ext_rcd_num NEQ 0xFF)
3091 {
3092 /* use the old extention record */
3093 phb_element[new_index].entry.ext_rcd_num = old_ext_rcd_num;
3094 }
3095 else
3096 {
3097 phb_element[new_index].entry.ext_rcd_num = pb_get_ext_record_number (type);
3098 }
3099 data[phb_ctb[type].alpha_len+13] = phb_element[new_index].entry.ext_rcd_num;
3100 }
3101 /* only number extention or subaddress could be store */
3102 else if (entry->subaddr[0] NEQ 0xFF)
3103 {
3104 file_id = pb_get_ext_file_id (type);
3105 if (old_ext_rcd_num NEQ 0xFF)
3106 {
3107 /* use the old extention record */
3108 phb_element[new_index].entry.ext_rcd_num = old_ext_rcd_num;
3109 }
3110 else
3111 {
3112 phb_element[new_index].entry.ext_rcd_num = pb_get_ext_record_number (0xFF);
3113 }
3114 data[phb_ctb[type].alpha_len+13] = phb_element[new_index].entry.ext_rcd_num;
3115 }
3116 #endif
3117 sim_result = pb_write_sim(type, phb_element[new_index].entry.index);
3118 #ifdef PHONEBOOK_EXTENSION
3119 if (sim_result NEQ PHB_FAIL)
3120 {
3121 if (phb_element[new_index].entry.ext_rcd_num != 0xFF)
3122 {
3123 pb_prepare_ext_data (phb_element[new_index].entry.number,
3124 phb_element[new_index].entry.len,
3125 phb_element[new_index].entry.subaddr,
3126 10,
3127 file_id);
3128 sim_result = pb_write_sim_ext(file_id, phb_element[new_index].entry.ext_rcd_num);
3129 }
3130 else if (old_ext_rcd_num NEQ 0xFF)
3131 {
3132 /* delete the old extention record */
3133 pb_rem_ext_record_flag (type, old_ext_rcd_num);
3134 pb_prepare_ext_data (NULL, 0, NULL, 0, file_id);
3135 sim_result = pb_write_sim_ext(SIM_EXT1, old_ext_rcd_num);
3136 }
3137 }
3138 #endif /* PHONEBOOK_EXTENSION */
3139 return(sim_result);
3140 }
3141 return PHB_OK;
3142 }
3143
3144 else if ((type EQ LDN) OR (type EQ LRN) OR (type EQ LMN))
3145 {
3146 cmhPHB_getAdrStr((char *)number,
3147 MAX_PHB_NUM_LEN - 1,
3148 entry->number,
3149 entry->len);
3150 if (pb_search_number(type, number, PHB_NEW_SEARCH,
3151 &first_id, &result, &found_entry) EQ PHB_OK)
3152 {
3153 if (result)
3154 pb_delete_record(type, (UBYTE)found_entry.index, &old_ext_rcd_num, FALSE);
3155 }
3156
3157 if (phb_ctb[type].used_rcd >= phb_ctb[type].max_rcd)
3158 {
3159 if ((cur_index = phb_ctb[type].first_rcd) EQ UNUSED_INDEX)
3160 return PHB_FAIL;
3161
3162 while (phb_l_element[cur_index].next_rcd NEQ UNUSED_BYTE_INDEX)
3163 cur_index = phb_l_element[cur_index].next_rcd;
3164 if (phb_l_element[cur_index].prev_rcd != UNUSED_BYTE_INDEX)
3165 phb_l_element[phb_l_element[cur_index].prev_rcd].next_rcd = UNUSED_BYTE_INDEX;
3166 }
3167
3168 else
3169 {
3170 if (pb_create_l_memory(&new_index) NEQ PHB_OK)
3171 return PHB_FAIL;
3172 phb_ctb[type].used_rcd++;
3173 cur_index = new_index;
3174 }
3175
3176 phb_l_element[cur_index].type = type;
3177
3178 /* copy record */
3179 /* if ((type EQ LDN) OR (type EQ LRN)) */
3180 /* copy call duration - not jet done */
3181 /* if ((type EQ LRN) OR (type EQ LMN)) */
3182 /* copy call identifier - not jet done */
3183
3184 memcpy((char *)phb_l_element[cur_index].entry.tag,
3185 (char *)entry->tag,
3186 PHB_MAX_TAG_LEN);
3187 phb_l_element[cur_index].entry.tag_len = entry->tag_len;
3188
3189 phb_l_element[cur_index].entry.year = entry->year;
3190 phb_l_element[cur_index].entry.month = entry->month;
3191 phb_l_element[cur_index].entry.day = entry->day;
3192 phb_l_element[cur_index].entry.hour = entry->hour;
3193 phb_l_element[cur_index].entry.minute = entry->minute;
3194 phb_l_element[cur_index].entry.second = entry->second;
3195 phb_l_element[cur_index].entry.len = entry->len;
3196 phb_l_element[cur_index].entry.ton_npi = entry->ton_npi;
3197 phb_l_element[cur_index].entry.line = entry->line;
3198 memcpy((char *)phb_l_element[cur_index].entry.number,
3199 (char *)entry->number,
3200 PHB_PACKED_NUM_LEN);
3201 phb_l_element[cur_index].entry.cc_id = entry->cc_id;
3202
3203 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
3204 if (phb_ctb[type].first_rcd EQ cur_index)
3205 {
3206 phb_l_element[cur_index].next_rcd = UNUSED_BYTE_INDEX;
3207 }
3208 else
3209 {
3210 phb_l_element[cur_index].next_rcd = (UBYTE)phb_ctb[type].first_rcd;
3211 }
3212
3213 /* If it is -1, gardening ! This is possible for the 1rst time a entry is added ??? */
3214 if (phb_ctb[type].first_rcd != UNUSED_BYTE_INDEX)
3215 {
3216 phb_l_element[phb_ctb[type].first_rcd].prev_rcd = (UBYTE)cur_index;
3217 }
3218
3219 phb_ctb[type].first_rcd = cur_index;
3220
3221 new_index = 1;
3222 while (cur_index NEQ UNUSED_BYTE_INDEX)
3223 {
3224 phb_l_element[cur_index].entry.index = (UBYTE)new_index;
3225 new_index++;
3226 cur_index = phb_l_element[cur_index].next_rcd;
3227 }
3228 if ( type EQ LDN )
3229 {
3230 /* ACI-SPR-16301: Write LND entry to 1 record of SIM, to keep it up
3231 to date Actually, the SIM entries will be overwritten by the LND data
3232 in RAM during switch off of the ME. This mechanism here is just to
3233 ensure the we retrieve more current data in the case of a SAT REFRESH
3234 or unexpected RESET. */
3235
3236 /* prepare entry */
3237 entrylen = pb_get_entry_len( entry->tag, PHB_MAX_TAG_LEN );
3238 tag_len = MINIMUM ( phb_ctb[type].alpha_len,
3239 entrylen) ;
3240 memset(data, 0xFF, sizeof(data));
3241 memcpy(data, entry->tag, tag_len);
3242 data[phb_ctb[type].alpha_len] = entry->len+1;
3243 data[phb_ctb[type].alpha_len+1] = entry->ton_npi;
3244 memcpy((char *)&data[phb_ctb[type].alpha_len+2],
3245 (char *)entry->number, 10);
3246 data[phb_ctb[type].alpha_len+12] = entry->cc_id;
3247
3248 /* always update the first entry */
3249 sim_result = pb_write_sim(type, 1);
3250
3251 return sim_result;
3252 }
3253 else
3254 {
3255 return PHB_OK;
3256 }
3257 }
3258 else /* unknown type */
3259 return PHB_FAIL;
3260 }
3261
3262
3263 /*
3264 +------------------------------------------------------------------------+
3265 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3266 | STATE : code ROUTINE : pb_delete_record |
3267 +------------------------------------------------------------------------+
3268
3269 PURPOSE : Delete a record from phonebook.
3270
3271 */
3272
3273 T_PHB_RETURN pb_delete_record(UBYTE type, UBYTE index, UBYTE *ext_rcd_num, BOOL permanent)
3274 {
3275 SHORT cur_index;
3276 UBYTE cur_byte_index, new_byte_index;
3277 UBYTE m,n;
3278 T_PHB_RETURN sim_result;
3279
3280 TRACE_FUNCTION ("pb_delete_record()");
3281
3282 /* check whether this phonebook exists */
3283 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3284 return PHB_FAIL;
3285
3286 if ((type EQ LDN) OR (type EQ LRN) OR (type EQ LMN))
3287 {
3288 cur_byte_index = (UBYTE)phb_ctb[type].first_rcd;
3289 while (cur_byte_index != UNUSED_BYTE_INDEX)
3290 {
3291 if (phb_l_element[cur_byte_index].entry.index EQ index)
3292 {
3293 phb_l_element[cur_byte_index].free = PHB_ELEMENT_FREE;
3294 pb_l_rcd_chain(type,
3295 (SHORT)phb_l_element[cur_byte_index].prev_rcd,
3296 (SHORT)cur_byte_index,
3297 (SHORT)phb_l_element[cur_byte_index].next_rcd);
3298 phb_ctb[type].used_rcd--;
3299
3300 /*
3301 * Delete Record in PCM, else the
3302 * record is back after restart
3303 */
3304 if (phb_ctb[type].mem == TE_MEMORY)
3305 {
3306 UBYTE data[SIZE_EF_LDN];
3307
3308 memset (data, 0xFF, SIZE_EF_LDN);
3309
3310 switch (type)
3311 {
3312 case LDN:
3313 TRACE_EVENT ("Delete LDN entry");
3314 pcm_WriteRecord((UBYTE *)EF_LDN_ID,
3315 (USHORT)(cur_byte_index+1),
3316 SIZE_EF_LDN,
3317 data);
3318 break;
3319 case LRN:
3320 TRACE_EVENT ("Delete LRN entry");
3321 pcm_WriteRecord((UBYTE *)EF_LRN_ID,
3322 (USHORT)(cur_byte_index+1),
3323 SIZE_EF_LRN,
3324 data);
3325 break;
3326 case LMN:
3327 TRACE_EVENT ("Delete LMN entry");
3328 pcm_WriteRecord((UBYTE *)EF_LMN_ID,
3329 (USHORT)(cur_byte_index+1),
3330 SIZE_EF_LMN,
3331 data);
3332 break;
3333 }
3334 }
3335 cur_byte_index = (UBYTE)phb_ctb[type].first_rcd;
3336 new_byte_index = 1;
3337 while (cur_byte_index != UNUSED_BYTE_INDEX)
3338 {
3339 phb_l_element[cur_byte_index].entry.index = new_byte_index;
3340 new_byte_index++;
3341 cur_byte_index = phb_l_element[cur_byte_index].next_rcd;
3342 }
3343 return PHB_OK;
3344 }
3345 cur_byte_index = phb_l_element[cur_byte_index].next_rcd;
3346 }
3347 }
3348 else /* SIM related phonebooks */
3349 {
3350 cur_index = phb_ctb[type].first_rcd;
3351
3352 while (cur_index NEQ UNUSED_INDEX)
3353 {
3354 if (phb_element[cur_index].entry.index EQ index)
3355 {
3356 phb_element[cur_index].free = PHB_ELEMENT_FREE;
3357 pb_rcd_chain(type,
3358 phb_element[cur_index].prev_rcd,
3359 cur_index,
3360 phb_element[cur_index].next_rcd);
3361 pb_name_chain(type,
3362 phb_element[cur_index].prev_trcd,
3363 cur_index,
3364 phb_element[cur_index].next_trcd);
3365 pb_num_chain(type,
3366 phb_element[cur_index].prev_nrcd,
3367 cur_index,
3368 phb_element[cur_index].next_nrcd);
3369
3370 if ((type EQ ADN) OR (type EQ FDN))
3371 {
3372 pb_mname_chain(type,
3373 phb_element[cur_index].prev_mtrcd,
3374 cur_index,
3375 phb_element[cur_index].next_mtrcd);
3376 pb_mnum_chain(type,
3377 phb_element[cur_index].prev_mnrcd,
3378 cur_index,
3379 phb_element[cur_index].next_mnrcd);
3380
3381 phb_ctb[ADN_FDN].used_rcd--;
3382 }
3383
3384 phb_ctb[type].used_rcd--;
3385
3386 n = (UBYTE)(phb_element[cur_index].entry.index - 1)/8;
3387 m = (UBYTE)(phb_element[cur_index].entry.index - 1)%8;
3388 phb_ctb[type].rcd_bitmap[n] ^= 0x01 << m;
3389
3390 if (phb_ctb[type].mem EQ SIM_MEMORY)
3391 {
3392 #ifdef PHONEBOOK_EXTENSION
3393 /* store the extention record */
3394 *ext_rcd_num = phb_element[cur_index].entry.ext_rcd_num;
3395 #endif
3396 /* write this record in SIM card */
3397 memset(data, 0xFF, sizeof(data));
3398 if (permanent)
3399 {
3400 sim_result = pb_write_sim(type, index);
3401 #ifdef PHONEBOOK_EXTENSION
3402 if ((sim_result NEQ PHB_FAIL) AND (*ext_rcd_num NEQ 0xFF))
3403 {
3404 pb_rem_ext_record_flag (type, *ext_rcd_num);
3405 pb_prepare_ext_data (NULL, 0, NULL, 0, pb_get_ext_file_id(type));
3406 sim_result = pb_write_sim_ext (pb_get_ext_file_id(type), *ext_rcd_num);
3407 }
3408 #endif
3409 return (sim_result);
3410 }
3411 }
3412 return PHB_OK;
3413 }
3414 cur_index = phb_element[cur_index].next_rcd;
3415 }
3416 }
3417
3418 return PHB_FAIL;
3419 }
3420
3421
3422
3423 void copy_phb_element ( T_PHB_RECORD *entry, T_PHB_AFB_ELEMENT phb_element )
3424 {
3425 memset (entry, 0xff, sizeof(T_PHB_RECORD));
3426
3427 entry->book = phb_element.type;
3428 entry->index = phb_element.entry.index;
3429 entry->tag_len = phb_element.entry.tag_len;
3430 memcpy((char *)entry->tag,
3431 (char *)phb_element.entry.tag,
3432 PHB_MAX_TAG_LEN);
3433 entry->len = phb_element.entry.len;
3434 entry->ton_npi = phb_element.entry.ton_npi;
3435 memcpy((char *)entry->number,
3436 (char *)phb_element.entry.number,
3437 PHB_PACKED_NUM_LEN);
3438 #ifdef PHONEBOOK_EXTENSION
3439 memcpy((char *)entry->subaddr,
3440 (char *)phb_element.entry.subaddr,
3441 PHB_PACKED_NUM_LEN);
3442 #endif
3443 entry->cc_id = phb_element.entry.cc_id;
3444 }
3445
3446
3447 void copy_phb_l_element ( T_PHB_RECORD *entry, T_PHB_RDM_ELEMENT phb_l_element )
3448 {
3449 memset (entry, 0xff, sizeof(T_PHB_RECORD));
3450
3451 entry->book = phb_l_element.type;
3452 entry->index = phb_l_element.entry.index;
3453 entry->tag_len = phb_l_element.entry.tag_len;
3454 memcpy((char *)entry->tag,
3455 (char *)phb_l_element.entry.tag,
3456 PHB_MAX_TAG_LEN);
3457 entry->len = phb_l_element.entry.len;
3458 entry->ton_npi = phb_l_element.entry.ton_npi;
3459 memcpy((char *)entry->number,
3460 (char *)phb_l_element.entry.number,
3461 PHB_PACKED_NUM_LEN);
3462 #ifdef PHONEBOOK_EXTENSION
3463 memcpy((char *)entry->subaddr,
3464 (char *)phb_l_element.entry.subaddr,
3465 PHB_PACKED_NUM_LEN);
3466 #endif
3467 entry->cc_id = phb_l_element.entry.cc_id;
3468 entry->line = phb_l_element.entry.line;
3469
3470 entry->year = phb_l_element.entry.year;
3471 entry->month = phb_l_element.entry.month;
3472 entry->day = phb_l_element.entry.day;
3473 entry->hour = phb_l_element.entry.hour;
3474 entry->minute = phb_l_element.entry.minute;
3475 entry->second = phb_l_element.entry.second;
3476 }
3477
3478
3479
3480
3481 /*
3482 +------------------------------------------------------------------------+
3483 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3484 | STATE : code ROUTINE : pb_read_phys_record |
3485 +------------------------------------------------------------------------+
3486
3487 PURPOSE : Read one record according to physical index from phonebook.
3488
3489 */
3490 T_PHB_RETURN pb_read_phys_record(UBYTE type, SHORT index, T_PHB_RECORD *entry)
3491 {
3492 SHORT cur_index;
3493 SHORT i;
3494
3495 /* TRACE_FUNCTION ("pb_read_phys_record()");*/
3496
3497 /* check whether this phonebook exists */
3498 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3499 return PHB_FAIL;
3500
3501 if (index > phb_ctb[type].max_rcd)
3502 return PHB_INVALID_IDX;
3503
3504 cur_index = phb_ctb[type].first_rcd;
3505 if (cur_index == UNUSED_INDEX)
3506 return PHB_FAIL;
3507
3508 if (type EQ ECC
3509 OR type EQ ADN
3510 OR type EQ FDN
3511 OR type EQ BDN
3512 OR type EQ UPN
3513 OR type EQ SDN )
3514 {
3515 for (i=0; i<phb_ctb[type].used_rcd; i++)
3516 {
3517 if (phb_element[cur_index].entry.index EQ index)
3518 {
3519 copy_phb_element (entry, phb_element[cur_index]);
3520 return PHB_OK;
3521 }
3522 cur_index = phb_element[cur_index].next_rcd;
3523 if (cur_index == UNUSED_INDEX)
3524 break;
3525 }
3526 }
3527
3528 else if (type EQ LDN
3529 OR type EQ LRN
3530 OR type EQ LMN)
3531 {
3532 for (i=0; i<phb_ctb[type].used_rcd; i++)
3533 {
3534 if (phb_l_element[cur_index].entry.index EQ index)
3535 {
3536 copy_phb_l_element (entry, phb_l_element[cur_index]);
3537 return PHB_OK;
3538 }
3539 cur_index = phb_l_element[cur_index].next_rcd;
3540 if (cur_index == UNUSED_INDEX)
3541 break;
3542 }
3543 }
3544
3545 return PHB_FAIL;
3546 }
3547
3548 /*
3549 +------------------------------------------------------------------------+
3550 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3551 | STATE : code ROUTINE : pb_read_index_record |
3552 +------------------------------------------------------------------------+
3553
3554 PURPOSE : Read one record according to index from phonebook.
3555
3556 */
3557
3558 T_PHB_RETURN pb_read_index_record(UBYTE type, SHORT index, T_PHB_RECORD *entry)
3559 {
3560 SHORT cur_index;
3561 SHORT i;
3562
3563 /* TRACE_FUNCTION ("pb_read_index_record()");*/
3564
3565 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3566 return PHB_FAIL;
3567
3568 if (index > phb_ctb[type].max_rcd)
3569 return PHB_INVALID_IDX;
3570
3571 cur_index = phb_ctb[type].first_rcd;
3572 if (cur_index == UNUSED_INDEX)
3573 return PHB_FAIL;
3574
3575 if (type EQ ECC
3576 OR type EQ ADN
3577 OR type EQ FDN
3578 OR type EQ BDN
3579 OR type EQ UPN
3580 OR type EQ SDN)
3581 {
3582 for (i=1; i<index; i++)
3583 {
3584 cur_index = phb_element[cur_index].next_rcd;
3585 if (cur_index == UNUSED_INDEX)
3586 return PHB_FAIL;
3587 }
3588 copy_phb_element (entry, phb_element[cur_index]);
3589 return PHB_OK;
3590 }
3591
3592 else if (type EQ LDN
3593 OR type EQ LRN
3594 OR type EQ LMN)
3595 {
3596 for (i=1; i<index; i++)
3597 {
3598 cur_index = phb_l_element[cur_index].next_rcd;
3599 if (cur_index == UNUSED_BYTE_INDEX)
3600 return PHB_FAIL;
3601 }
3602 copy_phb_l_element (entry, phb_l_element[cur_index]);
3603 return PHB_OK;
3604 }
3605
3606 return PHB_FAIL;
3607 }
3608
3609 /*
3610 +------------------------------------------------------------------------+
3611 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3612 | STATE : code ROUTINE : pb_read_alpha_record |
3613 +------------------------------------------------------------------------+
3614
3615 PURPOSE : Read one record according to alpha index from phonebook.
3616
3617 */
3618
3619 T_PHB_RETURN pb_read_alpha_record(UBYTE type, SHORT index, T_PHB_RECORD *entry)
3620 {
3621 SHORT cur_index;
3622 SHORT i;
3623
3624 /* TRACE_FUNCTION ("pb_read_alpha_record()");*/
3625
3626 if (type EQ ADN_FDN)
3627 {
3628 /* check whether this phonebook exists */
3629 if ((phb_ctb[ADN].mem EQ NO_PHB_ENTRY)
3630 AND (phb_ctb[FDN].mem EQ NO_PHB_ENTRY))
3631 return PHB_FAIL;
3632
3633 cur_index = phb_ctb[ADN].first_mtrcd;
3634 if (cur_index EQ UNUSED_INDEX)
3635 cur_index = phb_ctb[FDN].first_mtrcd;
3636 if (cur_index EQ UNUSED_INDEX)
3637 return PHB_FAIL;
3638
3639 for (i=1; i<index; i++)
3640 {
3641 cur_index = phb_element[cur_index].next_mtrcd;
3642 if (cur_index EQ UNUSED_INDEX)
3643 return PHB_FAIL;
3644 }
3645 copy_phb_element (entry, phb_element[cur_index]);
3646 return PHB_OK;
3647 }
3648 else if (type EQ ECC
3649 OR type EQ ADN
3650 OR type EQ FDN
3651 OR type EQ BDN
3652 OR type EQ SDN
3653 OR type EQ UPN)
3654 {
3655 /* check whether this phonebook exists */
3656 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3657 return PHB_FAIL;
3658
3659 cur_index = phb_ctb[type].first_trcd;
3660 if (cur_index EQ UNUSED_INDEX)
3661 return PHB_FAIL;
3662
3663 for (i=1; i<index; i++)
3664 {
3665 cur_index = phb_element[cur_index].next_trcd;
3666 if (cur_index EQ UNUSED_INDEX)
3667 return PHB_FAIL;
3668 }
3669 copy_phb_element (entry, phb_element[cur_index]);
3670 return PHB_OK;
3671 }
3672 else /* LDN, LRN, LMN */
3673 return PHB_FAIL;
3674 }
3675
3676 /*
3677 +------------------------------------------------------------------------+
3678 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3679 | STATE : code ROUTINE : pb_read_number_record |
3680 +------------------------------------------------------------------------+
3681
3682 PURPOSE : Read one record according to number index from phonebook.
3683
3684 */
3685
3686 T_PHB_RETURN pb_read_number_record(UBYTE type, SHORT index, T_PHB_RECORD *entry)
3687 {
3688 SHORT cur_index;
3689 SHORT i;
3690
3691 /* TRACE_FUNCTION ("pb_read_number_record()");*/
3692
3693 if (type EQ ADN_FDN)
3694 {
3695 /* check whether this phonebook exists */
3696 if ((phb_ctb[ADN].mem EQ NO_PHB_ENTRY)
3697 AND (phb_ctb[FDN].mem EQ NO_PHB_ENTRY))
3698 return PHB_FAIL;
3699
3700
3701 cur_index = phb_ctb[ADN].first_mnrcd;
3702 if (cur_index EQ UNUSED_INDEX)
3703 cur_index = phb_ctb[FDN].first_mnrcd;
3704 if (cur_index EQ UNUSED_INDEX)
3705 return PHB_FAIL;
3706
3707 for (i=1; i<index; i++)
3708 {
3709 cur_index = phb_element[cur_index].next_mnrcd;
3710 if (cur_index EQ UNUSED_INDEX)
3711 return PHB_FAIL;
3712 }
3713 copy_phb_element (entry, phb_element[cur_index]);
3714 return PHB_OK;
3715 }
3716 else if (type EQ ECC
3717 OR type EQ ADN
3718 OR type EQ FDN
3719 OR type EQ BDN
3720 OR type EQ SDN
3721 OR type EQ UPN)
3722 {
3723 /* check whether this phonebook exists */
3724 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3725 return PHB_FAIL;
3726
3727 cur_index = phb_ctb[type].first_nrcd;
3728 if (cur_index == UNUSED_INDEX)
3729 return PHB_FAIL;
3730
3731 for (i=1; i<index; i++)
3732 {
3733 cur_index = phb_element[cur_index].next_nrcd;
3734 if (cur_index == UNUSED_INDEX)
3735 return PHB_FAIL;
3736 }
3737 copy_phb_element (entry, phb_element[cur_index]);
3738 return PHB_OK;
3739 }
3740 else
3741 /* LDN, LRN, LMN */
3742 return PHB_FAIL;
3743 }
3744
3745 /*
3746 +------------------------------------------------------------------------+
3747 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3748 | STATE : code ROUTINE : pb_search_name |
3749 +------------------------------------------------------------------------+
3750
3751 PURPOSE : Search the string from phonebook
3752
3753 */
3754
3755 T_PHB_RETURN pb_search_name(T_ACI_CMD_SRC srcID,
3756 UBYTE type,
3757 T_ACI_PB_TEXT *search_tag,
3758 UBYTE mode,
3759 SHORT *first_ind,
3760 SHORT *result,
3761 T_PHB_RECORD *entry)
3762 {
3763 static SHORT ptr_index = UNUSED_INDEX;
3764 SHORT cur_index;
3765 SHORT index;
3766 int cmp_res;
3767 int cmp_len;
3768 int max_cmp_len;
3769
3770 /* TRACE_FUNCTION ("pb_search_name()");*/
3771
3772 if (type EQ ADN_FDN)
3773 {
3774 /* check whether this phonebook exists */
3775 if ((phb_ctb[ADN].mem EQ NO_PHB_ENTRY)
3776 AND (phb_ctb[FDN].mem EQ NO_PHB_ENTRY))
3777 return PHB_FAIL;
3778
3779 if ((phb_ctb[ADN].first_mtrcd EQ UNUSED_INDEX)
3780 AND (phb_ctb[FDN].first_mtrcd EQ UNUSED_INDEX))
3781 return PHB_FAIL;
3782 }
3783 else
3784 {
3785 /* check whether this phonebook exists */
3786 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
3787 return PHB_FAIL;
3788 }
3789
3790 /* search string */
3791 if ( mode EQ PHB_NEW_SEARCH )
3792 {
3793 TRACE_EVENT("pb_search_name() DEB: mode EQ PHB_NEW_SEARCH");
3794 ptr_index = UNUSED_INDEX;
3795 max_cmp_len = 0;
3796 index = 1;
3797 *result = 0;
3798
3799 if (type EQ ADN_FDN)
3800 {
3801 if (phb_ctb[ADN].first_mtrcd != UNUSED_INDEX)
3802 cur_index = phb_ctb[ADN].first_mtrcd;
3803 else
3804 cur_index = phb_ctb[FDN].first_mtrcd;
3805 }
3806 else
3807 cur_index = phb_ctb[type].first_trcd;
3808
3809 while (cur_index != UNUSED_INDEX)
3810 {
3811 /*
3812 this should not cause problems, because in both alphabets
3813 (GSM and ASCII) the most important chars are at the same
3814 positions (A-Z: 65-90 // a-z:97-122)
3815 */
3816 if (ext_compare_fct != NULL)
3817 {
3818 cmp_res = ext_compare_fct (phb_element[cur_index].entry.tag,
3819 phb_element[cur_index].entry.tag_len,
3820 search_tag->data,
3821 search_tag->len);
3822 }
3823 else
3824 {
3825 cmp_res = pb_cmp_phb_entry ( phb_element[cur_index].entry.tag,
3826 phb_element[cur_index].entry.tag_len,
3827 search_tag );
3828 }
3829
3830 #if defined(MFW) OR defined (FF_MMI_RIV)
3831 if (srcID EQ CMD_SRC_LCL)
3832 {
3833 /* if search string is before entry in alphabet */
3834 if (search_tag->len EQ 1 AND
3835 (cmp_res >= 0) AND (phb_element[cur_index].entry.tag[0] NEQ '\0'))
3836 {
3837 cmp_res = 0;
3838 }
3839 }
3840 else
3841 #endif
3842 {
3843 if (cmp_res EQ 0) /* If Searchstring matches the first letters of Phonebook */
3844 {
3845 if (search_tag->len <= phb_element[cur_index].entry.tag_len)
3846 ; /* MATCH */
3847 else
3848 cmp_res = search_tag->len + 1;
3849 }
3850 }
3851
3852 if (cmp_res EQ 0)
3853 {
3854 cmp_len = MINIMUM(phb_element[cur_index].entry.tag_len, search_tag->len);
3855 if ( cmp_len > max_cmp_len )
3856 {
3857 max_cmp_len = cmp_len;
3858 if ( ptr_index EQ UNUSED_INDEX )
3859 {
3860 /* save the index of the first found record */
3861 TRACE_EVENT("pb_search_name() DEB: first index");
3862 }
3863 ptr_index = cur_index;
3864 *first_ind = index;
3865 }
3866 (*result)++;
3867
3868 }
3869 if (type == ADN_FDN)
3870 cur_index = phb_element[cur_index].next_mtrcd;
3871 else
3872 cur_index = phb_element[cur_index].next_trcd;
3873 index++;
3874 }
3875 }
3876 else
3877 {
3878 TRACE_EVENT("pb_search_name() DEB: mode EQ PHB_NEXT_SEARCH");
3879 }
3880
3881 if ( ptr_index EQ UNUSED_INDEX )
3882 {
3883 TRACE_EVENT("pb_search_name() ERR: name not found");
3884 return PHB_FAIL;
3885 }
3886
3887 /* copy the found record */
3888 copy_phb_element( entry, phb_element[ptr_index] );
3889
3890 if (type == ADN_FDN)
3891 ptr_index = phb_element[ptr_index].next_mtrcd;
3892 else
3893 ptr_index = phb_element[ptr_index].next_trcd;
3894
3895 return PHB_OK;
3896 }
3897
3898 /*
3899 +------------------------------------------------------------------------+
3900 | PROJECT : MMI-Framework (8417) MODULE: PHB |
3901 | STATE : code ROUTINE : pb_search_number |
3902 +------------------------------------------------------------------------+
3903
3904 PURPOSE :
3905
3906 */
3907
3908 T_PHB_RETURN pb_search_number(UBYTE type,
3909 UBYTE *number,
3910 UBYTE mode,
3911 SHORT *first_ind,
3912 SHORT *result,
3913 T_PHB_RECORD *entry)
3914 {
3915 SHORT count = 0;
3916 static SHORT ptr_index;
3917 SHORT cur_index;
3918 UBYTE cur_byte_index;
3919
3920 UBYTE flag;
3921 SHORT index;
3922 CHAR cur_number[MAX_PHB_NUM_LEN];
3923 static CHAR search_number[MAX_PHB_NUM_LEN];
3924
3925 TRACE_FUNCTION ("pb_search_number()");
3926
3927 if (type EQ ADN_FDN)
3928 {
3929 /* check whether this phonebook exists */
3930 if ((phb_ctb[ADN].mem EQ NO_PHB_ENTRY)
3931 AND (phb_ctb[FDN].mem EQ NO_PHB_ENTRY))
3932 return PHB_FAIL;
3933
3934 if ((phb_ctb[ADN].first_mnrcd EQ UNUSED_INDEX)
3935 AND (phb_ctb[FDN].first_mnrcd EQ UNUSED_INDEX))
3936 return PHB_FAIL;
3937 }
3938 else
3939 {
3940 /* check whether this phonebook exists */
3941 if (phb_ctb[type].mem EQ NO_PHB_ENTRY AND type NEQ ECC)
3942 return PHB_FAIL;
3943 }
3944
3945 if (type EQ LDN
3946 OR type EQ LRN
3947 OR type EQ LMN)
3948 {
3949 *result = 0;
3950 if (!phb_ctb[type].used_rcd)
3951 return PHB_OK;
3952
3953 cur_byte_index = (UBYTE) phb_ctb[type].first_rcd;
3954
3955 while (cur_byte_index != UNUSED_BYTE_INDEX)
3956 {
3957 /* convert the number in BCD to string */
3958 cmhPHB_getAdrStr(cur_number,
3959 MAX_PHB_NUM_LEN - 1,
3960 phb_l_element[cur_byte_index].entry.number,
3961 phb_l_element[cur_byte_index].entry.len);
3962 if (!strcmp((char *)cur_number, (char *)number))
3963 {
3964 copy_phb_l_element(entry, phb_l_element[cur_byte_index]);
3965
3966 *result = 1;
3967 return PHB_OK;
3968 }
3969 cur_byte_index = phb_l_element[cur_byte_index].next_rcd;
3970 }
3971 }
3972
3973 /* check emergency call */
3974 if (type EQ ECC)
3975 {
3976 *result = 0;
3977
3978 /* if (!strcmp("112", (char *)number) || !strcmp("911", (char *)number) || !strcmp("999", (char *)number))
3979 {
3980 entry->book = ECC;
3981 entry->index = 1;
3982 entry->tag_len = 0;
3983 entry->tag[0] = 0;
3984 cmhPHB_getAdrBcd ( entry->number,
3985 &entry->len,
3986 PHB_PACKED_NUM_LEN, (char *)number );
3987 entry->ton_npi = 0xFF;
3988 entry->cc_id = 0xFF;
3989 *result = 1;
3990 return PHB_OK;
3991 }*/
3992
3993 if (!phb_ctb[type].used_rcd)
3994 return PHB_OK;
3995
3996 cur_index = phb_ctb[type].first_nrcd;
3997
3998 while (cur_index != UNUSED_INDEX)
3999 {
4000 /* convert the number in BCD to string */
4001 cmhPHB_getAdrStr(cur_number,
4002 PHB_PACKED_NUM_LEN - 1,
4003 phb_element[cur_index].entry.number,
4004 phb_element[cur_index].entry.len);
4005 if (!strcmp((char *)cur_number, (char *)number))
4006 {
4007 copy_phb_element (entry, phb_element[cur_index]);
4008 *result = 1;
4009 return PHB_OK;
4010 }
4011 cur_index = phb_element[cur_index].next_nrcd;
4012 }
4013 return PHB_OK;
4014 }
4015
4016 /* search phone number */
4017 if (mode EQ PHB_NEW_SEARCH)
4018 {
4019 count = 0;
4020 flag = 0;
4021 index = 1;
4022 strncpy(search_number, (char *)number, MAX_PHB_NUM_LEN-1);
4023 search_number[MAX_PHB_NUM_LEN-1] = '\0';
4024
4025 if (type EQ ADN_FDN)
4026 {
4027 if (phb_ctb[ADN].first_mnrcd != UNUSED_INDEX)
4028 cur_index = phb_ctb[ADN].first_mnrcd;
4029 else
4030 cur_index = phb_ctb[FDN].first_mnrcd;
4031 }
4032 else
4033 cur_index = phb_ctb[type].first_nrcd;
4034
4035 while (cur_index != UNUSED_INDEX)
4036 {
4037 /* convert the number in BCD to string */
4038 cmhPHB_getAdrStr(cur_number,
4039 MAX_PHB_NUM_LEN - 1,
4040 phb_element[cur_index].entry.number,
4041 phb_element[cur_index].entry.len);
4042
4043 if (pb_check_number(cur_number, (char *)number))
4044 {
4045 if (!flag)
4046 {
4047 ptr_index = cur_index; /* save the index of the first found record */
4048 *first_ind = index;
4049 flag = 1;
4050 }
4051 count++;
4052 }
4053 if (type EQ ADN_FDN)
4054 cur_index = phb_element[cur_index].next_mnrcd;
4055 else
4056 cur_index = phb_element[cur_index].next_nrcd;
4057 index++;
4058 }
4059
4060 *result = count;
4061 }
4062
4063 if (mode EQ PHB_NEXT_SEARCH AND count)
4064 {
4065 while (ptr_index != UNUSED_INDEX)
4066 {
4067 /* convert the number in BCD to string */
4068 cmhPHB_getAdrStr(cur_number,
4069 MAX_PHB_NUM_LEN - 1,
4070 phb_element[ptr_index].entry.number,
4071 phb_element[ptr_index].entry.len);
4072
4073 if (pb_check_number(cur_number, search_number))
4074 break;
4075
4076 if (type EQ ADN_FDN)
4077 ptr_index = phb_element[ptr_index].next_mnrcd;
4078 else
4079 ptr_index = phb_element[ptr_index].next_nrcd;
4080 }
4081 }
4082
4083 /* copy the found record */
4084 if (count)
4085 {
4086 copy_phb_element( entry, phb_element[ptr_index] );
4087 if (type EQ ADN_FDN)
4088 ptr_index = phb_element[ptr_index].next_mnrcd;
4089 else
4090 ptr_index = phb_element[ptr_index].next_nrcd;
4091 count--;
4092 }
4093 else
4094 return PHB_FAIL;
4095
4096 return PHB_OK;
4097 }
4098
4099 /*
4100 +------------------------------------------------------------------------+
4101 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4102 | STATE : code ROUTINE : pb_rcd_chain |
4103 +------------------------------------------------------------------------+
4104
4105 PURPOSE : Chain the element according to record number.
4106
4107 */
4108
4109 void pb_rcd_chain(UBYTE type,
4110 SHORT prev_index,
4111 SHORT cur_index,
4112 SHORT next_index)
4113 {
4114 /* TRACE_FUNCTION ("pb_rcd_chain()");*/
4115
4116 if ((phb_element[cur_index].prev_rcd EQ UNUSED_INDEX)
4117 AND (phb_element[cur_index].next_rcd EQ UNUSED_INDEX))
4118 {
4119 phb_ctb[type].first_rcd = UNUSED_INDEX;
4120 }
4121 else if ((phb_element[cur_index].prev_rcd NEQ UNUSED_INDEX)
4122 AND (phb_element[cur_index].next_rcd EQ UNUSED_INDEX))
4123 {
4124 phb_element[prev_index].next_rcd = UNUSED_INDEX;
4125 }
4126 else if ((phb_element[cur_index].prev_rcd EQ UNUSED_INDEX)
4127 AND (phb_element[cur_index].next_rcd NEQ UNUSED_INDEX))
4128 {
4129 phb_element[next_index].prev_rcd = UNUSED_INDEX;
4130 phb_element[cur_index].next_rcd = UNUSED_INDEX; /* ??? */
4131 phb_ctb[type].first_rcd = next_index;
4132 }
4133 else if ((phb_element[cur_index].prev_rcd NEQ UNUSED_INDEX)
4134 AND (phb_element[cur_index].next_rcd NEQ UNUSED_INDEX))
4135 {
4136 phb_element[prev_index].next_rcd = phb_element[cur_index].next_rcd;
4137 phb_element[next_index].prev_rcd = phb_element[cur_index].prev_rcd;
4138 }
4139 }
4140
4141 /*
4142 +------------------------------------------------------------------------+
4143 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4144 | STATE : code ROUTINE : pb_l_rcd_chain |
4145 +------------------------------------------------------------------------+
4146
4147 PURPOSE : Chain the element according to record number.
4148
4149 */
4150
4151 void pb_l_rcd_chain(UBYTE type,
4152 SHORT prev_index,
4153 SHORT cur_index,
4154 SHORT next_index)
4155 {
4156 /* TRACE_FUNCTION ("pb_l_rcd_chain()"); */
4157
4158 if ((phb_l_element[cur_index].prev_rcd EQ UNUSED_BYTE_INDEX)
4159 AND (phb_l_element[cur_index].next_rcd EQ UNUSED_BYTE_INDEX))
4160 {
4161 phb_ctb[type].first_rcd = UNUSED_INDEX;
4162 }
4163 else if ((phb_l_element[cur_index].prev_rcd NEQ UNUSED_BYTE_INDEX)
4164 AND (phb_l_element[cur_index].next_rcd EQ UNUSED_BYTE_INDEX))
4165 {
4166 phb_l_element[prev_index].next_rcd = UNUSED_BYTE_INDEX;
4167 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
4168 }
4169 else if ((phb_l_element[cur_index].prev_rcd EQ UNUSED_BYTE_INDEX)
4170 AND (phb_l_element[cur_index].next_rcd NEQ UNUSED_BYTE_INDEX))
4171 {
4172 phb_l_element[next_index].prev_rcd = UNUSED_BYTE_INDEX;
4173 phb_l_element[cur_index].next_rcd = UNUSED_BYTE_INDEX;
4174 phb_ctb[type].first_rcd = (UBYTE)next_index;
4175 }
4176 else if ((phb_l_element[cur_index].prev_rcd NEQ UNUSED_BYTE_INDEX)
4177 AND (phb_l_element[cur_index].next_rcd NEQ UNUSED_BYTE_INDEX))
4178 {
4179 phb_l_element[prev_index].next_rcd = phb_l_element[cur_index].next_rcd;
4180 phb_l_element[next_index].prev_rcd = phb_l_element[cur_index].prev_rcd;
4181 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
4182 phb_l_element[cur_index].prev_rcd = UNUSED_BYTE_INDEX;
4183 }
4184 }
4185
4186
4187 /*
4188 +------------------------------------------------------------------------+
4189 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4190 | STATE : code ROUTINE : pb_name_chain |
4191 +------------------------------------------------------------------------+
4192
4193 PURPOSE : Chain the element according to alpha string.
4194
4195 */
4196
4197 void pb_name_chain(UBYTE type,
4198 SHORT prev_index,
4199 SHORT cur_index,
4200 SHORT next_index)
4201 {
4202 SHORT ref_index;
4203 UBYTE flag;
4204
4205 /* TRACE_FUNCTION ("pb_name_chain()");*/
4206
4207 if ((phb_element[cur_index].prev_trcd EQ UNUSED_INDEX)
4208 AND (phb_element[cur_index].next_trcd EQ UNUSED_INDEX))
4209 {
4210 phb_ctb[type].first_trcd = UNUSED_INDEX;
4211 }
4212 else if ((phb_element[cur_index].prev_trcd NEQ UNUSED_INDEX)
4213 AND (phb_element[cur_index].next_trcd EQ UNUSED_INDEX))
4214 {
4215 phb_element[prev_index].next_trcd = UNUSED_INDEX;
4216 }
4217 else if ((phb_element[cur_index].prev_trcd EQ UNUSED_INDEX)
4218 AND (phb_element[cur_index].next_trcd NEQ UNUSED_INDEX))
4219 {
4220 phb_element[next_index].prev_trcd = UNUSED_INDEX;
4221 phb_ctb[type].first_trcd = next_index;
4222 phb_element[cur_index].next_trcd = UNUSED_INDEX;
4223 }
4224 else if ((phb_element[cur_index].prev_trcd NEQ UNUSED_INDEX)
4225 AND (phb_element[cur_index].next_trcd NEQ UNUSED_INDEX))
4226 {
4227 phb_element[prev_index].next_trcd = phb_element[cur_index].next_trcd;
4228 phb_element[next_index].prev_trcd = phb_element[cur_index].prev_trcd;
4229 }
4230
4231 if (phb_ctb[type].first_trcd EQ cur_index)
4232 {
4233 flag = 0;
4234
4235 ref_index = phb_element[cur_index].next_trcd;
4236 while (phb_element[ref_index].next_trcd)
4237 {
4238 if (!flag)
4239 {
4240 phb_ctb[type].first_trcd = ref_index;
4241 flag = 1;
4242 }
4243 ref_index = phb_element[ref_index].next_trcd;
4244 }
4245
4246 if (!phb_element[ref_index].next_trcd AND !flag)
4247 phb_ctb[type].first_trcd = UNUSED_INDEX;
4248 }
4249 }
4250
4251 /*
4252 +------------------------------------------------------------------------+
4253 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4254 | STATE : code ROUTINE : pb_num_chain |
4255 +------------------------------------------------------------------------+
4256
4257 PURPOSE : Chain the element according to phone number.
4258
4259 */
4260
4261 void pb_num_chain(UBYTE type,
4262 SHORT prev_index,
4263 SHORT cur_index,
4264 SHORT next_index)
4265 {
4266 SHORT ref_index;
4267 UBYTE flag;
4268
4269 /* TRACE_FUNCTION ("pb_num_chain()");*/
4270
4271 if ((phb_element[cur_index].prev_nrcd EQ UNUSED_INDEX)
4272 AND (phb_element[cur_index].next_nrcd EQ UNUSED_INDEX))
4273 {
4274 phb_ctb[type].first_nrcd = UNUSED_INDEX;
4275 }
4276 else if ((phb_element[cur_index].prev_nrcd NEQ UNUSED_INDEX)
4277 AND (phb_element[cur_index].next_nrcd EQ UNUSED_INDEX))
4278 {
4279 phb_element[prev_index].next_nrcd = UNUSED_INDEX;
4280 }
4281 else if ((phb_element[cur_index].prev_nrcd EQ UNUSED_INDEX)
4282 AND (phb_element[cur_index].next_nrcd NEQ UNUSED_INDEX))
4283 {
4284 phb_element[next_index].prev_nrcd = UNUSED_INDEX;
4285 phb_ctb[type].first_nrcd = next_index;
4286 }
4287 else if ((phb_element[cur_index].prev_nrcd NEQ UNUSED_INDEX)
4288 AND (phb_element[cur_index].next_nrcd NEQ UNUSED_INDEX))
4289 {
4290 phb_element[prev_index].next_nrcd = phb_element[cur_index].next_nrcd;
4291 phb_element[next_index].prev_nrcd = phb_element[cur_index].prev_nrcd;
4292 }
4293
4294 if (phb_ctb[type].first_nrcd EQ cur_index)
4295 {
4296 flag = 0;
4297
4298 ref_index = phb_element[cur_index].next_nrcd;
4299 while (phb_element[ref_index].next_nrcd)
4300 {
4301 if (!flag)
4302 {
4303 phb_ctb[type].first_nrcd = ref_index;
4304 flag = 1;
4305 }
4306 ref_index = phb_element[ref_index].next_nrcd;
4307 }
4308
4309 if (!phb_element[ref_index].next_nrcd AND !flag)
4310 phb_ctb[type].first_nrcd = UNUSED_INDEX;
4311 }
4312 }
4313
4314
4315 /*
4316 +------------------------------------------------------------------------+
4317 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4318 | STATE : code ROUTINE : pb_mname_chain |
4319 +------------------------------------------------------------------------+
4320
4321 PURPOSE : Chain the element according to merged alpha string.
4322
4323 */
4324
4325 void pb_mname_chain(UBYTE type,
4326 SHORT prev_index,
4327 SHORT cur_index,
4328 SHORT next_index)
4329 {
4330 SHORT ref_index;
4331 UBYTE flag;
4332
4333 /* TRACE_FUNCTION ("pb_mname_chain()");*/
4334
4335 if ((phb_element[cur_index].prev_mtrcd EQ UNUSED_INDEX)
4336 AND (phb_element[cur_index].next_mtrcd EQ UNUSED_INDEX))
4337 {
4338 phb_ctb[type].first_mtrcd = UNUSED_INDEX;
4339 }
4340 else if ((phb_element[cur_index].prev_mtrcd NEQ UNUSED_INDEX)
4341 AND (phb_element[cur_index].next_mtrcd EQ UNUSED_INDEX))
4342 {
4343 phb_element[prev_index].next_mtrcd = UNUSED_INDEX;
4344 }
4345 else if ((phb_element[cur_index].prev_mtrcd EQ UNUSED_INDEX)
4346 AND (phb_element[cur_index].next_mtrcd NEQ UNUSED_INDEX))
4347 {
4348 phb_element[next_index].prev_mtrcd = UNUSED_INDEX;
4349 if (phb_ctb[ADN].used_rcd != 0)
4350 phb_ctb[ADN].first_mtrcd = next_index;
4351 else
4352 phb_ctb[FDN].first_mtrcd = next_index;
4353 }
4354 else if ((phb_element[cur_index].prev_mtrcd NEQ UNUSED_INDEX)
4355 AND (phb_element[cur_index].next_mtrcd NEQ UNUSED_INDEX))
4356 {
4357 phb_element[prev_index].next_mtrcd = phb_element[cur_index].next_mtrcd;
4358 phb_element[next_index].prev_mtrcd = phb_element[cur_index].prev_mtrcd;
4359 }
4360
4361 if ((phb_ctb[ADN].first_mtrcd EQ cur_index)
4362 OR (phb_ctb[FDN].first_mtrcd EQ cur_index))
4363 {
4364 flag = 0;
4365
4366 ref_index = phb_element[cur_index].next_mtrcd;
4367 while (phb_element[ref_index].next_mtrcd)
4368 {
4369 if (!flag)
4370 {
4371 if (phb_ctb[ADN].used_rcd != 0)
4372 phb_ctb[ADN].first_mtrcd = ref_index;
4373 else
4374 phb_ctb[FDN].first_mtrcd = ref_index;
4375 flag = 1;
4376 }
4377 ref_index = phb_element[ref_index].next_mtrcd;
4378 }
4379
4380 if (!phb_element[ref_index].next_mtrcd AND !flag)
4381 {
4382 phb_ctb[ADN].first_mtrcd = UNUSED_INDEX;
4383 phb_ctb[FDN].first_mtrcd = UNUSED_INDEX;
4384 }
4385 }
4386 }
4387
4388 /*
4389 +------------------------------------------------------------------------+
4390 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4391 | STATE : code ROUTINE : pb_mnum_chain |
4392 +------------------------------------------------------------------------+
4393
4394 PURPOSE : Chain the element according to phone number.
4395
4396 */
4397
4398 void pb_mnum_chain(UBYTE type,
4399 SHORT prev_index,
4400 SHORT cur_index,
4401 SHORT next_index)
4402 {
4403 SHORT ref_index;
4404 UBYTE flag;
4405
4406 /* TRACE_FUNCTION ("pb_mnum_chain()");*/
4407
4408 if ((phb_element[cur_index].prev_mnrcd EQ UNUSED_INDEX)
4409 AND (phb_element[cur_index].next_mnrcd EQ UNUSED_INDEX))
4410 {
4411 phb_ctb[ADN].first_mnrcd = UNUSED_INDEX;
4412 phb_ctb[FDN].first_mnrcd = UNUSED_INDEX;
4413 }
4414 else if ((phb_element[cur_index].prev_mnrcd NEQ UNUSED_INDEX)
4415 AND (phb_element[cur_index].next_mnrcd EQ UNUSED_INDEX))
4416 {
4417 phb_element[prev_index].next_mnrcd = UNUSED_INDEX;
4418 }
4419 else if ((phb_element[cur_index].prev_mnrcd EQ UNUSED_INDEX)
4420 AND (phb_element[cur_index].next_mnrcd NEQ UNUSED_INDEX))
4421 {
4422 phb_element[next_index].prev_mnrcd = UNUSED_INDEX;
4423 if (phb_ctb[ADN].used_rcd != 0)
4424 phb_ctb[ADN].first_mnrcd = next_index;
4425 else
4426 phb_ctb[FDN].first_mnrcd = next_index;
4427 }
4428 else if ((phb_element[cur_index].prev_mnrcd NEQ UNUSED_INDEX)
4429 AND (phb_element[cur_index].next_mnrcd NEQ UNUSED_INDEX))
4430 {
4431 phb_element[prev_index].next_mnrcd = phb_element[cur_index].next_mnrcd;
4432 phb_element[next_index].prev_mnrcd = phb_element[cur_index].prev_mnrcd;
4433 }
4434
4435 if ((phb_ctb[ADN].first_mnrcd EQ cur_index)
4436 OR (phb_ctb[FDN].first_mnrcd EQ cur_index))
4437 {
4438 flag = 0;
4439
4440 ref_index = phb_element[cur_index].next_mnrcd;
4441 while (phb_element[ref_index].next_mnrcd)
4442 {
4443 if (!flag)
4444 {
4445 if (phb_ctb[ADN].used_rcd != 0)
4446 phb_ctb[ADN].first_mnrcd = ref_index;
4447 else
4448 phb_ctb[FDN].first_mnrcd = ref_index;
4449 flag = 1;
4450 }
4451 ref_index = phb_element[ref_index].next_mnrcd;
4452 }
4453
4454 if (!phb_element[ref_index].next_mnrcd AND !flag)
4455 {
4456 phb_ctb[ADN].first_mnrcd = UNUSED_INDEX;
4457 phb_ctb[FDN].first_mnrcd = UNUSED_INDEX;
4458 }
4459 }
4460 }
4461
4462 /*
4463 +------------------------------------------------------------------------+
4464 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4465 | STATE : code ROUTINE : pb_read_status |
4466 +------------------------------------------------------------------------+
4467
4468 PURPOSE :
4469
4470 */
4471
4472 T_PHB_RETURN pb_read_status(UBYTE type, UBYTE *service,
4473 SHORT *max_rcd, SHORT *used_rcd,
4474 UBYTE *tag_len, SHORT *avail_rcd)
4475 {
4476 SHORT i;
4477 SHORT count;
4478
4479 TRACE_FUNCTION ("pb_read_status()");
4480
4481 TRACE_EVENT_P1("PHB get status of phonebook: %d", type);
4482
4483 /* check whether this phonebook exists */
4484 if (phb_ctb[type].mem EQ NO_PHB_ENTRY)
4485 {
4486 TRACE_EVENT("Phonebook is empty: return PHB_FAIL");
4487 return PHB_FAIL;
4488 }
4489 *service = phb_ctb[type].service;
4490 *used_rcd = phb_ctb[type].used_rcd;
4491 /* ACI-SPR-9421 (mdf): reinstalled after storage increasement for phonebook */
4492 *max_rcd = phb_ctb[type].max_rcd;
4493 *tag_len = MINIMUM ( phb_ctb[type].alpha_len, PHB_MAX_TAG_LEN );
4494
4495 count = 0;
4496 switch (type)
4497 {
4498 case ECC:
4499 case ADN:
4500 case FDN:
4501 case SDN:
4502 case BDN:
4503 case ADN_FDN:
4504 case UPN:
4505 for (i=0; i<MAX_AFB_RECORDS; i++)
4506 {
4507 if (phb_element[i].free EQ PHB_ELEMENT_FREE)
4508 count++;
4509 }
4510 TRACE_EVENT_P1("free records from count=%d",count);
4511
4512 if ((phb_ctb[type].max_rcd-phb_ctb[type].used_rcd) >=count)
4513 {
4514 /* avail_rcd should be equal to free records not used records!!! */
4515 *avail_rcd = count;
4516 }
4517 else
4518 {
4519 *avail_rcd = phb_ctb[type].max_rcd - phb_ctb[type].used_rcd;
4520 }
4521 break;
4522 case LDN:
4523 case LRN:
4524 case LMN:
4525 *max_rcd = phb_ctb[type].max_rcd;
4526 *avail_rcd = phb_ctb[type].max_rcd - phb_ctb[type].used_rcd;
4527 break;
4528 }
4529 return PHB_OK;
4530 }
4531
4532
4533 /*
4534 +------------------------------------------------------------------+
4535 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4536 | STATE : code ROUTINE : pb_get_fdn_mode |
4537 +------------------------------------------------------------------+
4538
4539 PURPOSE :
4540
4541 */
4542 void pb_status_req(UBYTE *mode)
4543 {
4544 /* TRACE_FUNCTION ("pb_status_req()");*/
4545
4546 *mode = phb_stat;
4547 }
4548
4549
4550 /*
4551 +------------------------------------------------------------------+
4552 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4553 | STATE : code ROUTINE : pb_first_free |
4554 +------------------------------------------------------------------+
4555
4556 PURPOSE : On exit, "first_free" contains the index of the first free
4557 location in the specified phonebook.
4558
4559 */
4560 T_PHB_RETURN pb_first_free(
4561 UBYTE type,
4562 SHORT *first_free)
4563 {
4564 SHORT i,bit;
4565 UBYTE max_bitmap;
4566 UBYTE pos;
4567
4568 TRACE_FUNCTION ("pb_first_free()");
4569
4570 if (first_free EQ NULL)
4571 {
4572 ACI_ERR_DESC(ACI_ERR_CLASS_Cme,CME_ERR_Unknown);
4573 return(PHB_FAIL);
4574 }
4575
4576 switch (type)
4577 {
4578 case SDN:
4579 case ADN:
4580 case FDN:
4581 case BDN:
4582 case UPN:
4583 case ECC:
4584 switch (type)
4585 {
4586 case ADN: max_bitmap=MAX_ADN_BITMAP; break;
4587 case FDN: max_bitmap=MAX_FDN_BITMAP; break;
4588 case BDN: max_bitmap=MAX_BDN_BITMAP; break;
4589 case UPN: max_bitmap=MAX_UPN_BITMAP; break;
4590 case SDN: max_bitmap=MAX_SDN_BITMAP; break;
4591 case ECC: max_bitmap=MAX_ECC_BITMAP; break;
4592
4593 default:
4594 ACI_ERR_DESC(ACI_ERR_CLASS_Cme,CME_ERR_Unknown);
4595 return(PHB_FAIL);
4596 }
4597
4598 bit = 0;
4599 for (i=0; i<max_bitmap; i++)
4600 {
4601 pos = 0;
4602 while ((phb_ctb[type].rcd_bitmap[i] & (1<<pos)))
4603 {
4604 bit++;
4605 pos++;
4606 }
4607
4608 if ((bit%8) OR !pos)
4609 {
4610 if (bit>=phb_ctb[type].max_rcd)
4611 {
4612 *first_free=0;
4613 return(PHB_FULL);
4614 }
4615
4616 *first_free=bit+1;
4617 return(PHB_OK);
4618 }
4619 }
4620
4621 *first_free=0;
4622 return(PHB_FULL);
4623
4624 case LDN:
4625 case LMN:
4626 case LRN:
4627 /*
4628 * It is not possible to specify an index when writing to these
4629 * phonebooks. Whenever a number is added, it automatically goes
4630 * in the first entry of the list, hence it could be said that
4631 * the first free entry is always 1.
4632 */
4633 *first_free=1;
4634 return(PHB_OK);
4635
4636 default:
4637 break;
4638 }
4639
4640 ACI_ERR_DESC(ACI_ERR_CLASS_Cme,CME_ERR_Unknown);
4641 return(PHB_FAIL);
4642 }
4643
4644
4645 /*
4646 +--------------------------------------------------------------------+
4647 | PROJECT : MMI-Framework (8417) MODULE: PHB |
4648 | STATE : code ROUTINE : pb_switch_adn_fdn |
4649 +--------------------------------------------------------------------+
4650
4651 PURPOSE :
4652
4653 */
4654
4655 T_PHB_RETURN pb_switch_adn_fdn(UBYTE mode, T_ACI_CLASS aci_classFDN)
4656 {
4657 UBYTE classFDN = (UBYTE) CLASS_None;
4658 TRACE_FUNCTION("pb_switch_adn_fdn()");
4659
4660 pb_set_fdn_input_classtype (aci_classFDN);
4661
4662 if ((mode != FDN_DISABLE) AND (mode != FDN_ENABLE))
4663 return PHB_FAIL; /* never used */
4664
4665 fdn_mode = mode;
4666
4667 if ( fdn_classtype NEQ fdn_input_classtype)
4668 {
4669 fdn_classtype = fdn_input_classtype;
4670 classFDN = fdn_input_classtype;
4671 /* write to ffs */
4672 #ifndef _SIMULATION_
4673 if( ffs_fwrite("/mmi/fdnClassType", &classFDN, sizeof(classFDN)) < 1)
4674 {
4675 TRACE_FUNCTION("sAT_PlusCLCK: ME- failed to write ffs");
4676 }
4677 #endif
4678 }
4679
4680 pb_init_afb();
4681 pb_start_build(FALSE);
4682 return PHB_OK; /* never used */
4683 }
4684
4685
4686 /*
4687 +--------------------------------------------------------------------+
4688 | PROJECT : MMI-Framework (8417) MODULE : PHB |
4689 | STATE : code ROUTINE : cmpWild |
4690 +--------------------------------------------------------------------+
4691
4692 PURPOSE : compare two strings with wild character ('?') recognition
4693 in string1. Returns 0 on mismatch, otherwise 1. An empty
4694 string always match.
4695
4696 */
4697
4698 UBYTE cmpWild (char *s1, char *s2)
4699 {
4700 int i1, i2;
4701
4702 i1 = strlen(s1);
4703 i2 = strlen(s2);
4704
4705 if ( i1 != i2 )
4706 return 0;
4707
4708 while (i1 && i2)
4709 {
4710 i1--;
4711 i2--;
4712 if (s1[i1] != s2[i2] && s1[i1] != '?')
4713 return 0;
4714 }
4715
4716 return 1;
4717 }
4718
4719 /*
4720 +--------------------------------------------------------------------+
4721 | PROJECT : GSM-F&D (8411) MODULE : PHB |
4722 | STATE : code ROUTINE : cmpPHBString |
4723 +--------------------------------------------------------------------+
4724
4725 PURPOSE : get the length for PHB entry
4726 */
4727 int pb_get_entry_len ( const UBYTE *pb_tag, UBYTE max_pb_len )
4728 {
4729 int pb_len = 0;
4730 UBYTE inc_count = 1;
4731 BOOL ucs2 = FALSE;
4732 UBYTE chars = 0;
4733
4734 if (*pb_tag EQ 0x80)
4735 {
4736 ucs2 = TRUE;
4737 inc_count = 2; /* check two bytes */
4738 pb_len = 1; /* skip the 0x80 */
4739 }
4740 else if (*pb_tag EQ 0x81 OR *pb_tag EQ 0x82)
4741 {
4742 if (*pb_tag EQ 0x81)
4743 pb_len = 3; /* 0x80 + len + pointer */
4744 else
4745 pb_len = 4; /* 0x80 + len + 2xpointer */
4746
4747 chars = pb_tag[1];
4748 pb_tag += pb_len; /* go to data */
4749 while (chars)
4750 {
4751 if (*pb_tag++ & 0x80)
4752 pb_len+=2;
4753 else
4754 pb_len+=1;
4755
4756 pb_tag++;
4757 chars--;
4758 }
4759 return MINIMUM(pb_len,max_pb_len);
4760 }
4761
4762 while (pb_len < max_pb_len)
4763 {
4764 if (ucs2 EQ TRUE)
4765 {
4766 if (!(pb_len+1 < max_pb_len)) /* Check also if we traverse the upper bound */
4767 break; /* so only a "half" UCS2 element is remaining */
4768 }
4769 if (pb_tag[pb_len] EQ 0xFF)
4770 {
4771 /* one 0xFF indicates the end of a non UCS2 string */
4772 if (ucs2 EQ FALSE)
4773 {
4774 break;
4775 }
4776 /* two 0xFF indicates the end of a UCS2 string */
4777 if (pb_tag[pb_len + 1] EQ 0xFF)
4778 {
4779 break;
4780 }
4781 }
4782 pb_len += inc_count;
4783 }
4784
4785 return (pb_len);
4786 }
4787
4788 /*
4789 +--------------------------------------------------------------------+
4790 | PROJECT : MMI-Framework (8417) MODULE : PHB |
4791 | STATE : code ROUTINE : pb_cmp_phb_entry |
4792 +--------------------------------------------------------------------+
4793
4794 PURPOSE : compare PHB entry (SIM) with T_ACI_PB_TEXT.
4795 cannot compare pb_tag with search_tag return - 1
4796 if pb_tag < search_tag return value < 0
4797 if pb_tag = search_tag return value = 0
4798 if pb_tag > search_tag return value > 0
4799 */
4800 static int pb_cmp_phb_entry ( UBYTE *pb_tag,
4801 UBYTE pb_len,
4802 T_ACI_PB_TEXT *search_tag )
4803 {
4804 UBYTE cmp_len;
4805 UBYTE pb_tag_buf[PHB_MAX_TAG_LEN];
4806 UBYTE *cmp_pb_tag;
4807 UBYTE search_tag_buf[PHB_MAX_TAG_LEN];
4808 UBYTE *cmp_search_tag;
4809 int i;
4810
4811 cmp_len = MINIMUM ( pb_len, search_tag->len );
4812
4813 /* convert to lower cases, when not Unicode */
4814 if ( ( search_tag->cs EQ CS_Sim ) AND
4815 ( ( *search_tag->data NEQ 0x80 ) AND ( *pb_tag NEQ 0x80 ) ) )
4816 {
4817 for (i = 0; i < cmp_len; i++)
4818 pb_tag_buf[i] = (UBYTE)tolower((int)pb_tag[i]);
4819 cmp_pb_tag = pb_tag_buf;
4820
4821 for (i = 0; i < cmp_len; i++)
4822 search_tag_buf[i] = (UBYTE)tolower((int)search_tag->data[i]);
4823 cmp_search_tag = search_tag_buf;
4824 }
4825 else
4826 {
4827 cmp_pb_tag = pb_tag;
4828 cmp_search_tag = search_tag->data;
4829 }
4830 /* check the types */
4831 if ( search_tag->cs EQ CS_Sim )
4832 return ( cmpString ( cmp_pb_tag, cmp_search_tag, cmp_len ) );
4833
4834 if ( ( search_tag->cs == CS_Ucs2 ) AND ( *pb_tag EQ 0x80 ) )
4835 return ( memcmp ( cmp_pb_tag + 1, cmp_search_tag, cmp_len ) );
4836
4837 if ( ( search_tag->cs EQ CS_Ucs2 ) AND ( *pb_tag NEQ 0x80 ) )
4838 return pb_cmp2Bytes ( cmp_search_tag, cmp_pb_tag, cmp_len, 1 );
4839
4840 if ( ( search_tag->cs EQ CS_GsmDef ) AND ( *pb_tag EQ 0x80 ) )
4841 return pb_cmp2Bytes ( cmp_search_tag, cmp_pb_tag + 1 , cmp_len, 2 );
4842
4843 if ( ( search_tag->cs EQ CS_GsmDef ) AND ( *pb_tag NEQ 0x80 ) )
4844 {
4845 return ( memcmp ( cmp_pb_tag, cmp_search_tag, cmp_len ) );
4846 }
4847
4848 return ( -1 );
4849 }
4850
4851
4852 /*
4853 +--------------------------------------------------------------------+
4854 | PROJECT : MMI-Framework (8417) MODULE : PHB |
4855 | STATE : code ROUTINE : cmpString |
4856 +--------------------------------------------------------------------+
4857
4858 PURPOSE : compare two strings.
4859 if s1 < s2 return value < 0
4860 if s1 = s2 return value = 0
4861 if s1 > s2 return value > 0
4862 */
4863
4864 static int cmpString ( UBYTE *s1, UBYTE *s2, UBYTE len )
4865 {
4866 int n = 0;
4867
4868 /* TRACE_FUNCTION("cmpString()"); */ /* Called too often to trace */
4869
4870 if ((*s1 EQ 0x80) AND
4871 (*s2 NEQ 0x80) )
4872 {
4873 s1++;
4874 len--;
4875 return pb_cmp2Bytes(s1, s2, len, 1);
4876 }
4877 else if ((*s1 NEQ 0x80) AND
4878 (*s2 EQ 0x80) )
4879 {
4880 s2++;
4881 len--;
4882 return pb_cmp2Bytes(s1, s2, len, 2);
4883 }
4884 else
4885 {
4886 while (*s1 EQ *s2)
4887 {
4888 if (*s1 EQ 0xff)
4889 return 0;
4890 s1++;
4891 s2++;
4892 n++;
4893 if (n EQ len)
4894 return 0;
4895 }
4896
4897 if ((*s1 > *s2) AND (*s1 NEQ 0xff))
4898 return 1;
4899
4900 return -1;
4901 }
4902 }
4903
4904 /*
4905 +--------------------------------------------------------------------+
4906 | PROJECT : MMI-Framework (8417) MODULE : PHB |
4907 | STATE : code ROUTINE : pb_cmp2Bytes |
4908 +--------------------------------------------------------------------+
4909
4910 PURPOSE : compare two strings.
4911 if s1 < s2 return value < 0
4912 if s1 = s2 return value = 0
4913 if s1 > s2 return value > 0
4914
4915 flag = 1, s1 is unicode
4916 flag = 2, s2 is unicode
4917 */
4918
4919 static int pb_cmp2Bytes(UBYTE *s1, UBYTE *s2, UBYTE len, UBYTE flag)
4920 {
4921 int n = 0;
4922
4923 /* TRACE_FUNCTION("pb_cmp2Bytes()"); */
4924
4925 if (flag EQ 1)
4926 {
4927 while ( (*s1 EQ 0x00 OR *s1 EQ 0xFF ) AND ( *(s1+1) EQ *s2) )
4928 {
4929 if (*s1 EQ 0xff AND *(s1+1) EQ 0xFF)
4930 return 0;
4931 s1 += 2;
4932 s2++;
4933 n += 2;
4934
4935 if (n >= len)
4936 return 0;
4937 }
4938
4939 if ( ( *s1 > 0 AND *s1 NEQ 0xff ) OR
4940 ( !*s1 AND ( *(s1+1) > *s2 ) ) )
4941 return 1;
4942
4943 return -1;
4944 }
4945
4946 if (flag EQ 2)
4947 {
4948 while ((*s2 EQ 0x00 OR *s2 EQ 0xFF) AND (*s1 EQ *(s2+1)))
4949 {
4950 if (*s2 EQ 0xff AND *(s2+1) EQ 0xFF)
4951 return 0;
4952 s1++;
4953 s2 += 2;
4954 n += 2;
4955
4956 if (n >= len)
4957 return 0;
4958 }
4959
4960 if ((*s2 > 0 AND *s2 NEQ 0xff) OR
4961 (!*s2 AND (*(s2+1) > *s1)) )
4962 return -1;
4963
4964 return 1;
4965 }
4966 return -1;
4967 }
4968
4969 /*
4970 +--------------------------------------------------------------------+
4971 | PROJECT : MMI-Framework (8417) MODULE : PHB |
4972 | STATE : code ROUTINE : pb_check_number |
4973 +--------------------------------------------------------------------+
4974
4975 PURPOSE : compare two numbers. If they are same, return 1.
4976
4977 */
4978
4979 UBYTE pb_check_number(char *cur_number, char *number)
4980 {
4981 UBYTE len1;
4982 UBYTE len2;
4983
4984 len1 = strlen(cur_number);
4985 len2 = strlen((char *)number);
4986
4987 if (!len2)
4988 return 0; /* Bug Fix: the return value was "1" */
4989
4990 if ((len1>=6) && (len2>=6))
4991 {
4992 if (cmpWild (&cur_number[len1-6], (char *)&number[len2-6]) EQ 1)
4993 return 1;
4994 }
4995 else
4996 {
4997 if (cmpWild ((char *)cur_number, (char *)number) EQ 1)
4998 return 1;
4999 }
5000 return 0;
5001 }
5002
5003
5004 /*
5005 +--------------------------------------------------------------------+
5006 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5007 | STATE : code ROUTINE : pb_check_fdn |
5008 +--------------------------------------------------------------------+
5009
5010 PURPOSE : check whether phone number is in FDN phonebook.
5011
5012 */
5013 GLOBAL T_PHB_RETURN pb_check_fdn (UBYTE toa,
5014 const UBYTE *number)
5015 {
5016 SHORT cur_index;
5017 CHAR cur_number[MAX_PHB_NUM_LEN];
5018 CHAR new_number[MAX_PHB_NUM_LEN];
5019 UBYTE len1;
5020 UBYTE len2;
5021
5022 len1 = strlen((char *)number);
5023
5024 cur_index = phb_ctb[FDN].first_nrcd;
5025 while (cur_index != UNUSED_INDEX)
5026 {
5027 memset(new_number, 0, sizeof(new_number));
5028 cmhPHB_getAdrStr(cur_number,
5029 MAX_PHB_NUM_LEN - 1,
5030 phb_element[cur_index].entry.number,
5031 phb_element[cur_index].entry.len);
5032
5033 len2 = strlen((char *)cur_number);
5034 if (len1 < len2 OR phb_element[cur_index].entry.len EQ 0)
5035 {
5036 cur_index = phb_element[cur_index].next_nrcd;
5037 continue;
5038 }
5039 else
5040 {
5041 strncpy(new_number, (char *)number, len2);
5042 if (cmpWild ((char *)&cur_number, new_number) EQ 1)
5043 {
5044
5045 if ( toa NEQ 0 ) /* ACI-SPR-11927:check whether to test toa or not */
5046 {
5047 if ((toa NEQ phb_element[cur_index].entry.ton_npi) AND
5048 (phb_element[cur_index].entry.ton_npi NEQ 0xFF) ) /* VO patch 02.03.01 */
5049 {
5050 cur_index = phb_element[cur_index].next_nrcd;
5051 continue;
5052 }
5053 }
5054
5055 causeMod = P_CEER_mod; /* Clear module which was set for ceer */
5056 causeCeer = CEER_NotPresent; /* Reset cause - number to dial found in FDN list. */
5057 return PHB_OK;
5058 }
5059 }
5060
5061 cur_index = phb_element[cur_index].next_nrcd;
5062 }
5063 causeMod = P_CEER_sim; /* Set ceer module to sim */
5064 causeCeer = P_CEER_InvalidFDN; /* Set cause - number to dial not found in FDN list.*/
5065 return PHB_FAIL;
5066 }
5067
5068 /*
5069 +------------------------------------------------- -------------+
5070 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5071 | STATE : code ROUTINE : pb_exit |
5072 +---------------------------------------------------------------+
5073
5074 PURPOSE : Save the phonebook in SIM card.
5075
5076 */
5077
5078 void pb_exit()
5079 {
5080 TRACE_FUNCTION("pb_exit()");
5081
5082 pb_write_eeprom();
5083 if(pb_init_sync_sim(LDN) EQ FALSE)
5084 pb_finish_sync_sim(); /* this will otherwise be called after the last record written*/
5085 }
5086
5087
5088 /*
5089 +------------------------------------------------------------------+
5090 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5091 | STATE : code ROUTINE : pb_write_sim_cb |
5092 +------------------------------------------------------------------+
5093
5094
5095 PURPOSE : Call back for write phonebook in SIM card.
5096
5097 */
5098
5099 void pb_write_sim_cb(SHORT table_id)
5100 {
5101 UBYTE type;
5102
5103 TRACE_FUNCTION("pb_write_sim_cb()");
5104
5105 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
5106
5107 if (simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR)
5108 {
5109 TRACE_ERROR("pb_write_sim_cb(): error for writing");
5110 db_index = 0;
5111 phb_stat = PHB_READY;
5112 cmhPHB_StatIndication( PHB_WRITE_FAIL,
5113 (SHORT)cmhSIM_GetCmeFromSim( simShrdPrm.atb[table_id].errCode ),
5114 FALSE ); /* don't indicate for write */
5115 return;
5116 }
5117 if (db_index)
5118 {
5119 switch (simShrdPrm.atb[table_id].reqDataFld)
5120 {
5121 case SIM_ADN:
5122 type = ADN;
5123 break;
5124 case SIM_FDN:
5125 type = FDN;
5126 break;
5127 case SIM_BDN:
5128 type = BDN;
5129 break;
5130 case SIM_SDN:
5131 type = SDN;
5132 break;
5133 case SIM_MSISDN:
5134 type = UPN;
5135 break;
5136 default:
5137 return;
5138 }
5139 pb_delete_sim_book(type);
5140 }
5141 else
5142 {
5143 phb_stat = PHB_READY;
5144 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, FALSE );
5145 }
5146 }
5147
5148 /*
5149 +-----------------------------------------------------------------+
5150 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5151 | STATE : code ROUTINE : pb_write_sim |
5152 +-----------------------------------------------------------------+
5153
5154
5155 PURPOSE : Write phonebook in SIM card.
5156
5157 */
5158
5159 T_PHB_RETURN pb_write_sim(UBYTE type, UBYTE rcd_num)
5160 {
5161 SHORT table_id;
5162 USHORT data_id;
5163
5164 TRACE_FUNCTION("pb_write_sim()");
5165
5166 switch (type)
5167 {
5168 case ADN:
5169 data_id = SIM_ADN;
5170 break;
5171 case FDN:
5172 data_id = SIM_FDN;
5173 break;
5174 case BDN:
5175 data_id = SIM_BDN;
5176 break;
5177 case SDN:
5178 data_id = SIM_SDN;
5179 break;
5180 case UPN:
5181 data_id = SIM_MSISDN;
5182 break;
5183 case LDN:
5184 data_id = SIM_LND;
5185 break;
5186 default:
5187 return PHB_FAIL;
5188 }
5189
5190 table_id = psaSIM_atbNewEntry();
5191 if(table_id EQ NO_ENTRY)
5192 {
5193 TRACE_ERROR ("pb_write_sim(): no more table entries");
5194 return (PHB_FAIL);
5195 }
5196
5197 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
5198 simShrdPrm.atb[table_id].accType = ACT_WR_REC;
5199 simShrdPrm.atb[table_id].reqDataFld = data_id;
5200 simShrdPrm.atb[table_id].recNr = rcd_num;
5201 simShrdPrm.atb[table_id].dataLen = phb_ctb[type].alpha_len + 14;
5202 simShrdPrm.atb[table_id].exchData = data;
5203 simShrdPrm.atb[table_id].rplyCB = pb_write_sim_cb;
5204
5205 simShrdPrm.aId = table_id;
5206
5207 if(psaSIM_AccessSIMData() < 0)
5208 {
5209 TRACE_EVENT("pb_write_sim(): psaSIM_AccessSIMData() failed");
5210 return (PHB_FAIL);
5211 }
5212
5213 phb_stat = PHB_BUSY;
5214 cmhPHB_StatIndication ( PHB_BUSY, CME_ERR_NotPresent, FALSE );
5215
5216 return (PHB_EXCT);
5217 }
5218
5219
5220
5221 #ifdef PHONEBOOK_EXTENSION
5222 /*
5223 +----------------------------------------------------------------------+
5224 | PROJECT : MODULE : PHB |
5225 | STATE : code ROUTINE : pb_prepare_ext_data |
5226 +----------------------------------------------------------------------+
5227
5228
5229 PURPOSE : Prepare the data for the extention record.
5230 If NULL pointer is given for number and subaddress
5231 then the extention record will marked as unused
5232
5233 */
5234
5235
5236 LOCAL void pb_prepare_ext_data(UBYTE *number, UBYTE no_len,
5237 UBYTE *subaddr, UBYTE sub_len,
5238 USHORT file_id)
5239 {
5240 memset(data, 0xFF, sizeof(data));
5241
5242 if ((subaddr != NULL) AND (*subaddr != 0xFF))
5243 {
5244 TRACE_EVENT ("SUBADDRESS EXTENTION");
5245 data[0] = 1;
5246 data[1] = sub_len;
5247 memcpy (data + 2, subaddr, 11);
5248 }
5249 else if (number != NULL)
5250 {
5251 data[0] = 2;
5252 data[1] = no_len - 10;
5253 memcpy (data + 2, number + 10, no_len);
5254 }
5255 }
5256
5257
5258 /*
5259 +----------------------------------------------------------------------+
5260 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5261 | STATE : code ROUTINE : pb_write_sim_ext_cb |
5262 +----------------------------------------------------------------------+
5263
5264
5265 PURPOSE : Call back for write phonebook in SIM card.
5266
5267 */
5268
5269 void pb_write_sim_ext_cb(SHORT table_id)
5270 {
5271 /* USHORT ext_type;
5272 UBYTE rcd_num;*/
5273
5274 TRACE_FUNCTION("pb_write_sim_ext_cb");
5275
5276 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
5277
5278 if (simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR)
5279 {
5280 TRACE_ERROR("pb_write_sim_ext_cb (): FATAL ERROR");
5281 }
5282 }
5283
5284
5285 /*
5286 +-------------------------------------------------------------------+
5287 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5288 | STATE : code ROUTINE : pb_write_sim_ext |
5289 +-------------------------------------------------------------------+
5290
5291
5292 PURPOSE : Write phonebook in SIM card.
5293
5294 */
5295
5296 T_PHB_RETURN pb_write_sim_ext(USHORT data_id, UBYTE rcd_num)
5297 {
5298 SHORT table_id;
5299
5300 table_id = psaSIM_atbNewEntry();
5301
5302 if(table_id EQ NO_ENTRY)
5303 {
5304 TRACE_ERROR ("pb_write_sim_ext(): no more table entries");
5305 return (PHB_FAIL);
5306 }
5307
5308 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
5309 simShrdPrm.atb[table_id].accType = ACT_WR_REC;
5310 simShrdPrm.atb[table_id].reqDataFld = data_id;
5311 simShrdPrm.atb[table_id].recNr = rcd_num;
5312 simShrdPrm.atb[table_id].dataLen = 13;
5313 simShrdPrm.atb[table_id].exchData = data;
5314 simShrdPrm.atb[table_id].rplyCB = pb_write_sim_ext_cb;
5315
5316 simShrdPrm.aId = table_id;
5317
5318 if (psaSIM_AccessSIMData() < 0)
5319 {
5320 TRACE_ERROR("pb_write_sim_ext(): psaSIM_AccessSIMData() failed");
5321 return (PHB_FAIL);
5322 }
5323
5324 return (PHB_EXCT);
5325 }
5326 #endif /* PHONEBOOK_EXTENSION */
5327
5328 /*
5329 +------------------------------------------------------------------+
5330 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5331 | STATE : code ROUTINE : pb_write_eepron_req |
5332 +------------------------------------------------------------------+
5333
5334
5335 PURPOSE : Write phonebook in EEPROM.
5336
5337 */
5338
5339 void pb_write_eeprom()
5340 {
5341 SHORT ptr_index;
5342 UBYTE ptr_byte_index;
5343 int i;
5344 UBYTE count;
5345 EF_UPN *p = (EF_UPN *)data;
5346
5347 /* TRACE_FUNCTION ("pb_write_eeprom_req()"); */
5348
5349 /* Write Last Dialing Numbers */
5350 ptr_byte_index = (UBYTE)phb_ctb[LDN].first_rcd;
5351
5352 count = 0;
5353 for (i=0; i<phb_ctb[LDN].max_rcd; i++)
5354 {
5355 if (count < phb_ctb[LDN].used_rcd AND ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5356 {
5357 TRACE_EVENT_P1("--- LDN: copy to eeprom for ptr_byte_index %d", ptr_byte_index);
5358 pb_copy_ldn_record((SHORT)ptr_byte_index, 1);
5359 }
5360 else
5361 memset(&data[0], 0xFF, SIZE_EF_LDN);
5362
5363 if (pcm_WriteRecord((UBYTE *)EF_LDN_ID,
5364 (USHORT)(i+1),
5365 SIZE_EF_LDN,
5366 &data[0]) NEQ DRV_OK)
5367 break;
5368 if (ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5369 ptr_byte_index = phb_l_element[ptr_byte_index].next_rcd;
5370 count++;
5371 }
5372
5373 /* Write Last received Numbers */
5374 ptr_byte_index = (UBYTE)phb_ctb[LRN].first_rcd;
5375
5376 count = 0;
5377 for (i=0; i<phb_ctb[LRN].max_rcd; i++)
5378 {
5379 if (count < phb_ctb[LRN].used_rcd AND ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5380 pb_copy_lrn_record(ptr_byte_index, 1);
5381 else
5382 memset(&data[0], 0xFF, SIZE_EF_LRN);
5383
5384 if (pcm_WriteRecord((UBYTE *)EF_LRN_ID,
5385 (USHORT)(i+1),
5386 SIZE_EF_LRN,
5387 &data[0]) NEQ DRV_OK)
5388 break;
5389 if (ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5390 ptr_byte_index = phb_l_element[ptr_byte_index].next_rcd;
5391 count++;
5392 }
5393
5394 /* Write Last missed Numbers */
5395 ptr_byte_index = (UBYTE)phb_ctb[LMN].first_rcd;
5396
5397 count = 0;
5398 for (i=0; i<phb_ctb[LMN].max_rcd; i++)
5399 {
5400 if (count < phb_ctb[LMN].used_rcd AND ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5401 pb_copy_lmn_record(ptr_byte_index, 1);
5402 else
5403 memset(&data[0], 0xFF, SIZE_EF_LMN);
5404
5405 if (pcm_WriteRecord((UBYTE *)EF_LMN_ID,
5406 (USHORT)(i+1),
5407 SIZE_EF_LMN,
5408 &data[0]) NEQ DRV_OK)
5409 break;
5410 if (ptr_byte_index NEQ UNUSED_BYTE_INDEX)
5411 ptr_byte_index = phb_l_element[ptr_byte_index].next_rcd;
5412 count++;
5413 }
5414
5415 /* Write user person Numbers */
5416 if (phb_ctb[UPN].mem EQ TE_MEMORY)
5417 {
5418 ptr_index = phb_ctb[UPN].first_rcd;
5419
5420 count = 0;
5421 for (i=0; i<phb_ctb[UPN].max_rcd; i++)
5422 {
5423 if (count < phb_ctb[UPN].used_rcd AND ptr_index NEQ UNUSED_INDEX)
5424 {
5425 /* copy record */
5426 memcpy(p->alphId,
5427 phb_element[ptr_index].entry.tag,
5428 10*sizeof(UBYTE));
5429 p->len = phb_element[ptr_index].entry.len;
5430 p->numTp = phb_element[ptr_index].entry.ton_npi;
5431 memcpy(p->usrNum,
5432 phb_element[ptr_index].entry.number,
5433 10*sizeof(UBYTE));
5434 p->ccp = phb_element[ptr_index].entry.cc_id;
5435 }
5436 else
5437 memset(&data[0], 0xFF, SIZE_EF_UPN);
5438
5439 if (pcm_WriteRecord((UBYTE *)EF_UPN_ID,
5440 (USHORT)(i+1),
5441 SIZE_EF_UPN,
5442 &data[0]) NEQ DRV_OK)
5443 break;
5444 if (ptr_index NEQ UNUSED_INDEX)
5445 ptr_index = phb_element[ptr_index].next_rcd;
5446 count++;
5447 }
5448 }
5449 }
5450
5451
5452 /*
5453 +------------------------------------------------------------------+
5454 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5455 | STATE : code ROUTINE : pb_copy_ldn_record |
5456 +------------------------------------------------------------------+
5457
5458
5459 PURPOSE : Copy a LDN record.
5460 flag = 0: from EEPROM to local
5461 flag = 1: from local to EEPROM
5462
5463 */
5464
5465 void pb_copy_ldn_record(SHORT index, UBYTE flag)
5466 {
5467 EF_LDN *p = (EF_LDN *)data;
5468
5469 /* TRACE_FUNCTION ("pb_copy_ldn_record()");*/
5470 if (!flag)
5471 {
5472 phb_l_element[index].entry.year = p->year;
5473 phb_l_element[index].entry.month = p->month;
5474 phb_l_element[index].entry.day = p->day;
5475 phb_l_element[index].entry.hour = p->hour;
5476 phb_l_element[index].entry.minute = p->minute;
5477 phb_l_element[index].entry.second = p->second;
5478 phb_l_element[index].entry.len = p->len;
5479 phb_l_element[index].entry.ton_npi = p->numTp;
5480 memcpy((char *)phb_l_element[index].entry.number,
5481 (char *)&p->dldNum, 10);
5482 phb_l_element[index].entry.cc_id = p->ccp;
5483 }
5484 if (flag EQ 1)
5485 {
5486 p->calDrMsb = 0xFF;
5487 p->calDrLsb = 0xFF;
5488 p->year = phb_l_element[index].entry.year;
5489 p->month = phb_l_element[index].entry.month;
5490 p->day = phb_l_element[index].entry.day;
5491 p->hour = phb_l_element[index].entry.hour;
5492 p->minute = phb_l_element[index].entry.minute;
5493 p->second = phb_l_element[index].entry.second;
5494 p->len = phb_l_element[index].entry.len;
5495 p->numTp = phb_l_element[index].entry.ton_npi;
5496 memcpy((char *)p->dldNum,
5497 (char *)phb_l_element[index].entry.number, 10);
5498 p->ccp = phb_l_element[index].entry.cc_id;
5499 p->ext1 = 0xFF;
5500 }
5501 }
5502
5503
5504 /*
5505 +------------------------------------------------------------------+
5506 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5507 | STATE : code ROUTINE : pb_copy_lrn_record |
5508 +------------------------------------------------------------------+
5509
5510
5511 PURPOSE : Copy a LRN record.
5512 flag = 0: from EEPROM to local
5513 flag = 1: from local to EEPROM
5514
5515 */
5516
5517 void pb_copy_lrn_record(SHORT index, UBYTE flag)
5518 {
5519 EF_LRN *p = (EF_LRN *)data;
5520
5521 /* TRACE_FUNCTION ("pb_copy_lrn_record()");*/
5522
5523 if (!flag)
5524 {
5525 phb_l_element[index].entry.year = p->year;
5526 phb_l_element[index].entry.month = p->month;
5527 phb_l_element[index].entry.day = p->day;
5528 phb_l_element[index].entry.hour = p->hour;
5529 phb_l_element[index].entry.minute = p->minute;
5530 phb_l_element[index].entry.second = p->second;
5531 phb_l_element[index].entry.len = p->len;
5532 phb_l_element[index].entry.ton_npi = p->numTp;
5533 memcpy((char *)phb_l_element[index].entry.number,
5534 (char *)p->dldNum, 10);
5535 phb_l_element[index].entry.cc_id = p->ccp;
5536 }
5537 if (flag EQ 1)
5538 {
5539 p->calDrMsb = 0xFF;
5540 p->calDrLsb = 0xFF;
5541 p->year = phb_l_element[index].entry.year;
5542 p->month = phb_l_element[index].entry.month;
5543 p->day = phb_l_element[index].entry.day;
5544 p->hour = phb_l_element[index].entry.hour;
5545 p->minute = phb_l_element[index].entry.minute;
5546 p->second = phb_l_element[index].entry.second;
5547 p->id = 0xFF;
5548 p->len = phb_l_element[index].entry.len;
5549 p->numTp = phb_l_element[index].entry.ton_npi;
5550 memcpy((char *)p->dldNum,
5551 (char *)phb_l_element[index].entry.number, 10);
5552 p->ccp = phb_l_element[index].entry.cc_id;
5553 p->ext1 = 0xFF;
5554 }
5555 }
5556
5557
5558 /*
5559 +------------------------------------------------------------------+
5560 | PROJECT : MMI-Framework (8417) MODULE : PHB |
5561 | STATE : code ROUTINE : pb_copy_lmn_record |
5562 +------------------------------------------------------------------+
5563
5564
5565 PURPOSE : Copy a LMN record.
5566 flag = 0: from EEPROM to local
5567 flag = 1: from local to EEPROM
5568
5569 */
5570
5571 void pb_copy_lmn_record(SHORT index, UBYTE flag)
5572 {
5573 EF_LMN *p = (EF_LMN *)data;
5574
5575 /* TRACE_FUNCTION ("pb_copy_lmn_record()");*/
5576
5577 if (!flag)
5578 {
5579 phb_l_element[index].entry.year = p->year;
5580 phb_l_element[index].entry.month = p->month;
5581 phb_l_element[index].entry.day = p->day;
5582 phb_l_element[index].entry.hour = p->hour;
5583 phb_l_element[index].entry.minute = p->minute;
5584 phb_l_element[index].entry.second = p->second;
5585 phb_l_element[index].entry.len = p->len;
5586 phb_l_element[index].entry.ton_npi = p->numTp;
5587 memcpy((char *)phb_l_element[index].entry.number,
5588 (char *)p->dldNum, 10);
5589 phb_l_element[index].entry.cc_id = p->ccp;
5590 }
5591 if (flag EQ 1)
5592 {
5593 p->year = phb_l_element[index].entry.year;
5594 p->month = phb_l_element[index].entry.month;
5595 p->day = phb_l_element[index].entry.day;
5596 p->hour = phb_l_element[index].entry.hour;
5597 p->minute = phb_l_element[index].entry.minute;
5598 p->second = phb_l_element[index].entry.second;
5599 p->id = 0xFF;
5600 p->len = phb_l_element[index].entry.len;
5601 p->numTp = phb_l_element[index].entry.ton_npi;
5602 memcpy((char *)p->dldNum,
5603 (char *)phb_l_element[index].entry.number, 10);
5604 p->ccp = phb_l_element[index].entry.cc_id;
5605 p->ext1 = 0xFF;
5606 }
5607 }
5608
5609 /*
5610 +------------------------------------------------------------------------+
5611 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5612 | STATE : code ROUTINE : pb_delete_book |
5613 +------------------------------------------------------------------------+
5614
5615 PURPOSE : Delete a phonebook in SIM card.
5616
5617 */
5618
5619 T_PHB_RETURN pb_delete_book(UBYTE book)
5620 {
5621 SHORT cur_index;
5622
5623 TRACE_FUNCTION("pb_delete_book()");
5624
5625 /* check whether this phonebook exists */
5626 if (phb_ctb[book].mem EQ NO_PHB_ENTRY)
5627 return PHB_FAIL;
5628
5629 phb_stat = PHB_BUSY;
5630 cmhPHB_StatIndication ( PHB_BUSY, CME_ERR_NotPresent, FALSE );
5631
5632 cur_index = phb_ctb[book].first_rcd;
5633 while (cur_index != UNUSED_INDEX)
5634 {
5635 phb_element[cur_index].free = PHB_ELEMENT_FREE;
5636 if ((book EQ ADN) OR (book EQ FDN))
5637 {
5638 pb_mname_chain(book,
5639 phb_element[cur_index].prev_mtrcd,
5640 cur_index,
5641 phb_element[cur_index].next_mtrcd);
5642 pb_mnum_chain(book,
5643 phb_element[cur_index].prev_mnrcd,
5644 cur_index,
5645 phb_element[cur_index].next_mnrcd);
5646 }
5647 cur_index = phb_element[cur_index].next_rcd;
5648 }
5649 phb_ctb[book].used_rcd = 0;
5650 /* phb_ctb[book].first_rcd = UNUSED_INDEX;*/
5651 phb_ctb[book].first_trcd = UNUSED_INDEX;
5652 phb_ctb[book].first_nrcd = UNUSED_INDEX;
5653 phb_ctb[book].first_mtrcd = UNUSED_INDEX; /* ??? */
5654 phb_ctb[book].first_mnrcd = UNUSED_INDEX; /* ??? */
5655 switch (book)
5656 {
5657 case ADN:
5658 memset(phb_ctb[book].rcd_bitmap, 0, MAX_ADN_BITMAP);
5659 break;
5660 case FDN:
5661 memset(phb_ctb[book].rcd_bitmap, 0, MAX_FDN_BITMAP);
5662 break;
5663 case BDN:
5664 memset(phb_ctb[book].rcd_bitmap, 0, MAX_BDN_BITMAP);
5665 break;
5666 case SDN:
5667 memset(phb_ctb[book].rcd_bitmap, 0, MAX_SDN_BITMAP);
5668 break;
5669 case UPN:
5670 memset(phb_ctb[book].rcd_bitmap, 0, MAX_UPN_BITMAP);
5671 break;
5672 default:
5673 break;
5674 }
5675 pb_delete_sim_book(book);
5676 return PHB_OK;
5677 }
5678
5679 /*
5680 +------------------------------------------------------------------------+
5681 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5682 | STATE : code ROUTINE : pb_delete_sim_book |
5683 +------------------------------------------------------------------------+
5684
5685 PURPOSE : Delete a phonebook in SIM card.
5686
5687 */
5688
5689 void pb_delete_sim_book(UBYTE book)
5690 {
5691 if (!db_index)
5692 {
5693 db_index = phb_ctb[book].first_rcd;
5694 phb_ctb[book].first_rcd = UNUSED_INDEX;
5695 }
5696 else
5697 db_index = phb_element[db_index].next_rcd;
5698 if (db_index != UNUSED_INDEX)
5699 {
5700 memset(data, 0xFF, sizeof(data));
5701 if (pb_write_sim(book, phb_element[db_index].entry.index) EQ PHB_FAIL)
5702 {
5703 db_index = 0;
5704 phb_stat = PHB_READY;
5705 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, FALSE );
5706 }
5707 }
5708 else
5709 {
5710 db_index = 0;
5711 phb_stat = PHB_READY;
5712 cmhPHB_StatIndication ( PHB_READY, CME_ERR_NotPresent, FALSE );
5713 }
5714 }
5715
5716
5717
5718 /*
5719 +------------------------------------------------------------------------+
5720 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5721 | STATE : code ROUTINE : pb_update_ecc_fu |
5722 +------------------------------------------------------------------------+
5723
5724 PURPOSE : Read emergency call numbers from SIM card.
5725
5726 */
5727 #ifdef SIM_TOOLKIT
5728 BOOL pb_update_ecc_fu(int ref, T_SIM_FILE_UPDATE_IND *fu)
5729 {
5730
5731 BOOL found = FALSE;
5732 UBYTE i;
5733 TRACE_FUNCTION ("pb_update_ecc_fu()");
5734
5735 for (i = 0; i < (int)fu->val_nr; i++)
5736 {
5737 if (!found AND (fu->file_id[i] EQ SIM_ECC))
5738 {
5739 found = TRUE;
5740 }
5741 }
5742
5743 if (found)
5744 {
5745 simShrdPrm.fuRef = ref;
5746 pb_update_ecc();
5747 return FALSE; /* reading files */
5748 }
5749 else
5750 {
5751 return TRUE; /* nothing to do */
5752 }
5753 }
5754 #endif
5755
5756 /*
5757 +------------------------------------------------------------------------+
5758 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5759 | STATE : code ROUTINE : pb_update_ecc |
5760 +------------------------------------------------------------------------+
5761
5762 PURPOSE : Read emergency call numbers from SIM card.
5763
5764 */
5765
5766 void pb_update_ecc(void)
5767 {
5768 TRACE_FUNCTION("pb_update_ecc()");
5769 if ((fdn_mode != NO_OPERATION) AND (simShrdPrm.fuRef EQ -1))
5770 return;
5771
5772 phb_ctb[ECC].mem = SIM_MEMORY;
5773
5774 phb_ctb[ECC].type = ECC;
5775 phb_ctb[ECC].first_trcd = UNUSED_INDEX;
5776 pb_read_sim_ecc();
5777
5778 }
5779
5780 /*
5781 +------------------------------------------------------------------------+
5782 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5783 | STATE : code ROUTINE : pb_read_sim_ecc |
5784 +------------------------------------------------------------------------+
5785
5786 PURPOSE : Read EC number from SIM card.
5787
5788 */
5789
5790 void pb_read_sim_ecc (void)
5791 {
5792 TRACE_FUNCTION ("pb_read_sim_ecc()");
5793
5794 if (pb_read_sim_dat(SIM_ECC, NOT_PRESENT_8BIT, (UBYTE)256) EQ FALSE ) /* give the max length 256 */
5795 pb_read_eeprom_ecc();
5796 }
5797
5798 /*
5799 +------------------------------------------------------------------------+
5800 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5801 | STATE : code ROUTINE : pb_read_eeprom_ecc |
5802 +------------------------------------------------------------------------+
5803
5804 PURPOSE : Read EC number from EEPROM.
5805
5806 */
5807
5808 void pb_read_eeprom_ecc (void)
5809 {
5810 EF_ECC efecc;
5811 UBYTE *data_ptr;
5812 UBYTE version;
5813 int i;
5814
5815 phb_ctb[ECC].mem = TE_MEMORY;
5816 phb_ctb[ECC].type = ECC;
5817 phb_ctb[ECC].max_rcd = MAX_ECC_RCD;
5818 phb_ctb[ECC].first_trcd = UNUSED_INDEX;
5819
5820 if (pcm_ReadFile((UBYTE *)EF_ECC_ID,
5821 SIZE_EF_ECC,
5822 (UBYTE *)&efecc,
5823 &version) EQ DRV_OK)
5824 {
5825
5826
5827
5828 { /* workaround when invalid data stored on PCM */
5829 CHAR ecc_number[MAX_PHB_NUM_LEN];
5830 int j;
5831
5832 data_ptr = &efecc.ecc1[0];
5833
5834 for (i=0; i < phb_ctb[ECC].max_rcd; i++)
5835 {
5836 if (*data_ptr NEQ 0xFF)
5837 {
5838 cmhPHB_getAdrStr (ecc_number,
5839 MAX_PHB_NUM_LEN - 1,
5840 data_ptr,
5841 3);
5842 for (j = 0; j < 3; j++)
5843 {
5844 if (!isdigit (ecc_number[j]))
5845 {
5846 TRACE_EVENT_P2 ("[ERR] pb_read_eeprom_ecc(): invalid character found %c (%d)",
5847 ecc_number[j], i);
5848 return;
5849 }
5850 }
5851 }
5852 data_ptr += 3;
5853 }
5854 } /* workaround end */
5855
5856 data_ptr = &efecc.ecc1[0];
5857
5858 for (i=0; i < phb_ctb[ECC].max_rcd; i++)
5859 {
5860 pb_copy_ecc_entry(data_ptr, (UBYTE)i);
5861 data_ptr += 3;
5862 }
5863 }
5864 }
5865
5866 /*
5867 +------------------------------------------------------------------------+
5868 | PROJECT : MMI-Framework (8417) MODULE: PHB |
5869 | STATE : code ROUTINE : pb_copy_ecc_entry |
5870 +------------------------------------------------------------------------+
5871
5872 PURPOSE : Read EC number from EEPROM.
5873
5874 */
5875
5876 void pb_copy_ecc_entry (UBYTE *ecc, UBYTE num)
5877 {
5878 SHORT index;
5879 /* TRACE_FUNCTION("pb_copy_ecc_entry()"); */
5880 if (*ecc NEQ 0xff)
5881 {
5882 /* search a free element in phonebook element table */
5883 if (pb_create_memory(&index) NEQ PHB_OK)
5884 return;
5885
5886 phb_ctb[ECC].used_rcd++;
5887 phb_ctb[ECC].rcd_bitmap[0] |= (UBYTE)(0x01 << num);
5888
5889 phb_element[index].type = ECC;
5890 phb_element[index].entry.index = (UBYTE)(num+1);
5891 phb_element[index].entry.len = 3;
5892 memcpy(phb_element[index].entry.number, ecc, 3);
5893
5894 pb_record_sort(index);
5895 pb_num_sort(index);
5896
5897 phb_element[index].prev_trcd = UNUSED_INDEX;
5898 phb_element[index].next_trcd = UNUSED_INDEX;
5899 }
5900 }
5901
5902
5903 /*
5904 +----------------------------------------------------------------------+
5905 | PROJECT: MMI-Framework (8417) MODULE: PHB |
5906 | STATE : code ROUTINE: pb_read_sim_dat |
5907 +----------------------------------------------------------------------+
5908
5909
5910 PURPOSE : Request to read SIM card.
5911
5912 */
5913
5914 BOOL pb_read_sim_dat(USHORT data_id, UBYTE len, UBYTE max_length)
5915 {
5916 SHORT table_id;
5917
5918 TRACE_FUNCTION ("pb_read_sim_dat()");
5919
5920 table_id = psaSIM_atbNewEntry();
5921
5922 if(table_id NEQ NO_ENTRY)
5923 {
5924 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
5925 simShrdPrm.atb[table_id].accType = ACT_RD_DAT;
5926 simShrdPrm.atb[table_id].reqDataFld = data_id;
5927 simShrdPrm.atb[table_id].dataOff = 0;
5928 simShrdPrm.atb[table_id].dataLen = len;
5929 simShrdPrm.atb[table_id].recMax = max_length;
5930 simShrdPrm.atb[table_id].exchData = NULL;
5931 simShrdPrm.atb[table_id].rplyCB = pb_read_sim_dat_cb;
5932
5933 simShrdPrm.aId = table_id;
5934
5935 if(psaSIM_AccessSIMData() < 0)
5936 {
5937 TRACE_EVENT("FATAL ERROR");
5938 return FALSE;
5939 }
5940 return TRUE;
5941 }
5942 return FALSE;
5943 }
5944
5945 /*
5946 +----------------------------------------------------------------------+
5947 | PROJECT: MMI-Framework (8417) MODULE: PHB |
5948 | STATE : code ROUTINE: pb_read_sim_dat_cb |
5949 +----------------------------------------------------------------------+
5950
5951
5952 PURPOSE : Call back for SIM read.
5953
5954 */
5955 void pb_read_sim_dat_cb(SHORT table_id)
5956 {
5957 int i;
5958 UBYTE *data_ptr;
5959
5960 TRACE_FUNCTION ("pb_read_sim_dat_cb()");
5961
5962 switch (simShrdPrm.atb[table_id].reqDataFld)
5963 {
5964 case SIM_ECC:
5965 data_ptr = simShrdPrm.atb[table_id].exchData;
5966 if ( simShrdPrm.atb[table_id].errCode EQ SIM_NO_ERROR )
5967 {
5968 phb_ctb[ECC].max_rcd = (SHORT)simShrdPrm.atb[table_id].dataLen/3;
5969
5970 for (i=0; i < phb_ctb[ECC].max_rcd; i++)
5971 {
5972 pb_copy_ecc_entry(data_ptr, (UBYTE)i);
5973 data_ptr += 3;
5974 }
5975 #ifdef SIM_TOOLKIT
5976 if (simShrdPrm.fuRef >= 0)
5977 {
5978 psaSAT_FUConfirm (simShrdPrm.fuRef, SIM_FU_SUCCESS);
5979 }
5980 #endif
5981 }
5982 else
5983 {
5984 #ifdef SIM_TOOLKIT
5985 if (simShrdPrm.fuRef >= 0)
5986 {
5987 psaSAT_FUConfirm (simShrdPrm.fuRef, SIM_FU_ERROR);
5988 }
5989 #endif
5990 pb_read_eeprom_ecc();
5991 }
5992 break;
5993
5994 case SIM_SST:
5995 data_ptr = simShrdPrm.atb[table_id].exchData;
5996 if ( simShrdPrm.atb[table_id].errCode EQ SIM_NO_ERROR )
5997 {
5998 /* copy SIM service table */
5999 memset(sim_service_table, 0, sizeof(sim_service_table));
6000 memcpy(sim_service_table,
6001 simShrdPrm.atb[table_id].exchData,
6002 MINIMUM(MAX_SRV_TBL, simShrdPrm.atb[table_id].dataLen));
6003
6004 /* initialisation of the all SIM phonebooks */
6005 pb_sat_update_reset(SIM_ADN);
6006 pb_sat_update_reset(SIM_FDN);
6007 pb_sat_update_reset(SIM_BDN);
6008 pb_sat_update_reset(SIM_SDN);
6009 pb_sat_update_reset(SIM_MSISDN);
6010
6011 /* start reading SIM phonebook */
6012 pb_start_build(FALSE);
6013 }
6014 else
6015 pb_start_build(FALSE);
6016 break;
6017
6018 default:
6019 break;
6020 }
6021 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
6022 }
6023
6024 /*
6025 +----------------------------------------------------------------------+
6026 | PROJECT: MMI-Framework MODULE : PHB |
6027 | STATE : code ROUTINE: pb_set_compare |
6028 +----------------------------------------------------------------------+
6029
6030
6031 PURPOSE : set a external MMI compare function for phonebook entries
6032 */
6033
6034 void pb_set_compare_fct (T_PHB_EXT_CMP_FCT compare_fct)
6035 {
6036 ext_compare_fct = compare_fct;
6037 }
6038
6039 /*
6040 +----------------------------------------------------------------------+
6041 | PROJECT: MMI-Framework MODULE : PHB |
6042 | STATE : code ROUTINE: pb_get_fdn_input_classtype |
6043 +----------------------------------------------------------------------+
6044
6045
6046 PURPOSE : get fdn_input_classtype
6047 */
6048
6049 T_ACI_CLASS pb_get_fdn_input_classtype (void)
6050 {
6051 return fdn_input_classtype;
6052 }
6053
6054 /*
6055 +----------------------------------------------------------------------+
6056 | PROJECT: MMI-Framework MODULE : PHB |
6057 | STATE : code ROUTINE: pb_set_fdn_input_classtype |
6058 +----------------------------------------------------------------------+
6059
6060
6061 PURPOSE : set fdn_input_classtype
6062 */
6063
6064 void pb_set_fdn_input_classtype (T_ACI_CLASS classtype)
6065 {
6066 fdn_input_classtype = classtype;
6067 }
6068
6069 /*
6070 +----------------------------------------------------------------------+
6071 | PROJECT: MMI-Framework MODULE : PHB |
6072 | STATE : code ROUTINE: pb_get_fdn_classtype |
6073 +----------------------------------------------------------------------+
6074
6075
6076 PURPOSE : get fdn_classtype
6077 */
6078
6079 T_ACI_CLASS pb_get_fdn_classtype (void)
6080 {
6081 return fdn_classtype;
6082 }
6083
6084 /*
6085 +----------------------------------------------------------------------+
6086 | PROJECT: MMI-Framework MODULE : PHB |
6087 | STATE : code ROUTINE: pb_set_fdn_classtype |
6088 +----------------------------------------------------------------------+
6089
6090
6091 PURPOSE : set fdn_classtype
6092 */
6093
6094 void pb_set_fdn_classtype (T_ACI_CLASS classtype)
6095 {
6096 fdn_classtype = classtype;
6097 }
6098
6099
6100 /*
6101 +----------------------------------------------------------------------+
6102 | PROJECT: MMI-Framework MODULE : PHB |
6103 | STATE : code ROUTINE: pb_get_fdn_mode |
6104 +----------------------------------------------------------------------+
6105
6106 PURPOSE : get fdn_mode
6107 */
6108
6109 UBYTE pb_get_fdn_mode (void)
6110
6111 {
6112 return fdn_mode;
6113 }
6114 /*
6115 +----------------------------------------------------------------------+
6116 | PROJECT: MMI-Framework MODULE : PHB |
6117 | STATE : code ROUTINE: pb_set_fdn_mode |
6118 +----------------------------------------------------------------------+
6119
6120 PURPOSE : set fdn_mode
6121 */
6122
6123 void pb_set_fdn_mode (UBYTE fdnmode)
6124
6125 {
6126 fdn_mode = fdnmode;
6127 }
6128
6129 #endif /* #ifndef TI_PS_FFS_PHB */