comparison gsm-fw/g23m-aci/aci/phb.c @ 775:eedbf248bac0

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