comparison src/aci2/bmi/mmiHomezone.c @ 120:3c2acfa1a72f

src/aci2/bmi: file renames to make filename case consistent
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 07 Oct 2016 03:46:05 +0000
parents src/aci2/bmi/MmiHomezone.c@93999a60b835
children
comparison
equal deleted inserted replaced
119:b92a33c204b6 120:3c2acfa1a72f
1 /*******************************************************************************
2
3 CONDAT (UK)
4
5 ********************************************************************************
6
7 This software product is the property of Condat (UK) Ltd and may not be
8 disclosed to any third party without the express permission of the owner.
9
10 ********************************************************************************
11
12 $Project name: Basic MMI
13 $Project code: BMI
14 $Module:
15 $File: MmiHomezone.c
16 $Revision: 1.0
17
18 $Author: Condat(UK)
19 $Date: 15/02/02
20
21 ********************************************************************************
22
23 Description: Homezone functionality in MMI
24
25
26
27 ********************************************************************************
28
29 $History: MmiHomezone.c
30
31 15/02/02 Original Condat(UK) BMI version.
32 28/05/02 Latest Condat(UK) BMI version
33
34 Mar 14, 2006 DR: OMAPS00061468 - x0035544.
35 Description: SAT 27.22.4.22.2 SET UP IDLE MODE TEXT (Icon support) fails
36 Solution : In the function homezoneUpdateDisplay(), additional parameter has been added to the
37 function call addSatMessage() under the flag FF_MMI_SAT_ICON to support SAT Icon for IDLE TEXT display.
38
39 Dec 15, 2005 REF: MMI-FIX-OMAPS00058684 x0035544
40 Description: OMAPS00045726 / MMI-FIX-30439 Follow-Up : ifdef for FF Home Zone forgotten.
41 Solution: Added Feature flag FF_HOMEZONE for the function sms_homezoneCBToggle(U8 Activate_CB)
42 in this file as it has got the prototype for this function.
43
44 Jun 14, 2005 REF: MMI-FIX-30439 x0018858
45 Description: The homezone/cityzone tags were not being displayed properly.
46 Solution: Modified to save the tags properly in caches and also made the
47 appropriate modifications to update the same properly during mobility.
48
49 $End
50
51 *******************************************************************************/
52 #include <string.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55
56 #if defined (NEW_FRAME)
57
58 #include "typedefs.h"
59 #include "vsi.h"
60 #include "pei.h"
61 #include "custom.h"
62 #include "gsm.h"
63
64 #else
65
66 #include "STDDEFS.H"
67 #include "custom.h"
68 #include "gsm.h"
69 #include "vsi.h"
70
71 #endif
72
73
74 #include "mfw_sys.h"
75
76 #include "mfw_mfw.h"
77 #include "mfw_win.h"
78 #include "mfw_kbd.h"
79 /* SPR#1428 - SH - New Editor changes */
80 #ifndef NEW_EDITOR
81 #include "mfw_edt.h"
82 #endif
83 #include "mfw_lng.h"
84 #include "mfw_icn.h"
85 #include "mfw_phb.h"
86 #include "mfw_sim.h"
87 #include "mfw_nm.h"
88 #include "ksd.h"
89 #include "psa.h"
90 #include "mfw_sms.h"
91 #include "mfw_smsi.h"
92 #include "mfw_mnu.h"
93 #include "mfw_sat.h"
94 #include "mfw_tim.h"
95 #include "mfw_cphs.h"
96
97 #include "MmiMmi.h"
98 #include "MmiDummy.h"
99 #include "MmiDialogs.h"
100 #include "MmiLists.h"
101
102 #include "MmiMain.h"
103 #include "MmiStart.h"
104 #include "MmiPins.h"
105 #include "MmiMenu.h"
106 #include "MmiSoftKeys.h"
107 #include "MmiSounds.h"
108 #include "mmiCall.h"
109
110 #include "MmiBookController.h"
111
112 #include "MmiIdle.h"
113 #include "Mmiicons.h"
114 #include "MmiNetwork.h"
115 #include "mmiSmsBroadcast.h"
116 #include "MmiHomezone.h"
117
118 #include "cus_aci.h"
119
120 #include "prim.h"
121 #ifndef PCM_2_FFS
122 #include "pcm.h"
123 #endif
124
125
126 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
127 // enable HZ trace
128 //#undef TRACE_MMIHOMEZONE
129 #define TRACE_MMIHOMEZONE 1
130
131 T_homezone_data homezoneData;
132 extern T_SMSCB_DATASTORE g_smscb_data; /* storage for Cell Broadcast lists */
133 static int hzFlag = 0; //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
134
135 //Dec 14, 2005 REF: MMI-FIX-OMAPS00058684 x0035544
136 #ifdef FF_HOMEZONE
137 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
138 // Externed the function for activation\deactivation of Homezone.
139 extern void sms_homezoneCBToggle(U8 Activate_CB);
140 #endif
141 //void sms_homezoneCBToggle(U8 Activate_CB);
142
143 /*******************************************************************************
144
145 LOCALLY REFERENCED FUNCTIONS
146
147 *******************************************************************************/
148
149 void homezoneReadParams();
150 void homezoneLocate();
151 static U32 calculateDecimal( char *string, int length );
152 static U32 readHexFromSimfile( UBYTE *simFile, int length );
153 static void writeHexToSimfile( UBYTE *simFile, U32 value, int length );
154
155 /*******************************************************************************
156
157 $Function: homezoneInit
158
159 $Description: Initialise homezone data structure. Reset the recent cache.
160
161 $Returns:
162
163 $Arguments:
164 *******************************************************************************/
165
166 void homezoneInit()
167 {
168 T_homezone_data *data = &homezoneData;
169 USHORT cacheIndex;
170 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
171 // Added the following local variables.
172 //begin 30439
173 UBYTE version;
174 USHORT max_rcd;
175 EF_HZCACHE cache;
176 //end 30439
177
178 TRACE_FUNCTION("homezoneInit()");
179
180 /* Set all data to 0 */
181
182 memset((UBYTE *)data, 0, sizeof(T_homezone_data));
183
184 data->current_zone = HZ_NOT_IN_ZONE; // 0xFF = not in a homezone
185 data->recent_cell_index = HZ_RECENT_MAX-1; // Next entry will loop round & be at start of cache
186
187 /* Set up recent cell cache */
188
189 for (cacheIndex = 0; cacheIndex<HZ_RECENT_MAX; cacheIndex++)
190 {
191 data->recent_cell[cacheIndex] = 0;
192 data->recent_cell_zone[cacheIndex] = HZ_NOT_IN_ZONE;
193 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
194 //begin 30439
195 /* Read cache from PCM */
196 if (pcm_ReadRecord((UBYTE *)EF_HZCACHE_ID,
197 (USHORT)(cacheIndex+1),
198 SIZE_EF_HZCACHE,
199 (UBYTE *)&cache,
200 &version,
201 &max_rcd) NEQ DRV_OK)
202 {
203 TRACE_EVENT ("Init cache read from PCM wrong");
204 break; /* read error */
205 }
206 else
207 {
208 if (cache.cid[0] != 0xFF AND cache.cid[1] != 0xFF)
209 {
210 data->recent_cell[cacheIndex] = readHexFromSimfile(&cache.cid[0],2);
211 data->recent_cell_zone[cacheIndex] = cache.zone;
212 }
213 }
214 TRACE_EVENT_P3("Init cache %d: CID %X, zone %X",cacheIndex, data->recent_cell[cacheIndex], data->recent_cell_zone[cacheIndex]);
215 //end 30439
216 }
217
218 data->new_cell_res = FALSE;
219
220 return;
221 }
222
223
224 /*******************************************************************************
225
226 $Function: homezoneReadSim
227
228 $Description: Read homezone data in from SIM. Checks to see if conditions (SIM,
229 network) are correct for homezone; switches it off if not.
230
231 $Returns: None.
232
233 $Arguments: read_again - if this is HZ_READ_ONCE_ONLY, then SIM fields will not
234 be read in again if they have already been read in once.
235 If this is HZ_READ_SIM_AGAIN, they will be read in anyway.
236
237 *******************************************************************************/
238
239 void homezoneReadSim(UBYTE read_again)
240 {
241 T_homezone_data *data = &homezoneData;
242 char IMSI[17];
243 char MNC_MCC[6];
244 T_ACI_RETURN result;
245 USHORT networkIndex;
246 UBYTE networkOK;
247 USHORT tries;
248
249 /* Check if homezone is switched off */
250
251 if (data->received == HZ_RECEIVED_HZ_OFF)
252 return;
253
254 /* SPR877 - If read_again specifies that SIM data should not be re-read, exit from function
255 * provided we have read it once. */
256
257 if (read_again == HZ_READ_ONCE_ONLY && data->received & HZ_RECEIVED_SIMDATA)
258 return;
259
260 TRACE_FUNCTION("homezoneReadSim()");
261
262 /* Check if network operator is in list */
263
264 networkOK = FALSE;
265
266 tries = 0;
267
268 while ((result = qAT_PlusCIMI(CMD_SRC_LCL, IMSI)) != AT_CMPL && tries < 5)
269 {
270 tries++;
271 }
272
273 strncpy(MNC_MCC, IMSI, 5);
274 MNC_MCC[5] =0; //terminate string
275
276 #ifdef TRACE_MMIHOMEZONE
277 TRACE_EVENT_P1("MNC_MCC: %s", (char *)MNC_MCC);
278 #endif
279
280 for (networkIndex=0; networkIndex<HZ_PERMITTED_NETWORKS; networkIndex++)
281 {
282 if (!strncmp((char *)MNC_MCC, homezoneMNC_MCC[networkIndex],5))
283 {
284 #ifdef TRACE_MMIHOMEZONE
285 TRACE_EVENT_P1("Matches entry %d", networkIndex);
286 #endif
287 networkOK = TRUE;
288 }
289 }
290 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
291 //begin 30439
292 /* Attempt to read first sim field */
293 if (read_again == HZ_READ_SIM_AGAIN)
294 hzFlag = 1;
295 //end 30439
296
297 if (networkOK)
298 {
299 if (!Read_Sim(HZ_SIM_PARAMETERS, 0, HZ_SIM_PARAMETERS_SIZE, data->buffer))
300 {
301 TRACE_EVENT("SIM read error 1: Homezone OFF"); /* SIM field not present, switch off homezone */
302 data->received = HZ_RECEIVED_HZ_OFF;
303 hzFlag = 0; //Jun 14, 2005 REF: MMI-FIX-30439 x0018858 - Seting the variable
304 }
305 }
306 else
307 {
308 TRACE_EVENT("Wrong network: Homezone OFF"); /* Network not in list, switch off homezone */
309 data->received = HZ_RECEIVED_HZ_OFF;
310 hzFlag = 0; //Jun 14, 2005 REF: MMI-FIX-30439 x0018858 - Seting the variable
311 }
312
313 return;
314 }
315
316
317 /*******************************************************************************
318
319 $Function: homezoneReadSimCb
320
321 $Description: Callback, called when read sim has occurred. Fills up the homezone
322 data structure with the appropriate values retrieved from SIM.
323
324 $Returns: None.
325
326 $Arguments: field - the SIM field that was just read
327 record - the record in the SIM field that was read
328 result - the result code returned - 0 for successful.
329 *******************************************************************************/
330
331 void homezoneReadSimCb(USHORT field, USHORT record, USHORT result)
332 {
333 T_homezone_data *data = &homezoneData;
334 T_homezone *homezone = data->homezone;
335 UBYTE *simFile;
336 USHORT fileIndex;
337 USHORT hzIndex;
338 UBYTE keepLooking;
339 U8 Activate_cb =0; //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
340 //To activate/deactivate homezoneCB
341 TRACE_FUNCTION("homezoneReadSimCb()");
342
343 #ifdef TRACE_MMIHOMEZONE
344 TRACE_EVENT_P2("Have just read SIM file: %x record %d", field, record);
345 #endif
346
347 /* Read in general homezone data. If reading first SIM field fails, switch homezone off */
348
349 if (field==HZ_SIM_PARAMETERS)
350 {
351 /* check SIM read result for homezone parameter */
352 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
353 //begin 30439
354 //Modified the conditional statement
355 //if (result)
356 if (result != 0x80FF)
357 //end 30439
358 {
359 TRACE_EVENT("SIM read error 2: Homezone OFF");
360 data->received = HZ_RECEIVED_HZ_OFF;
361 hzFlag = 0; //Jun 14, 2005 REF: MMI-FIX-30439 x0018858 -Setting the variable
362 return;
363 }
364 homezoneReadParams();
365 /*homezoneActivateCB();*/ /* Switch on cell broadcast */
366 /* SH - this is already done at startup */
367 record = HZ_CACHE_MAX;
368 }
369
370 /* Read in records for each homezone cache */
371
372 /* check SIM read result for hoemzone cache */
373 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
374 //begin 30439
375 //Modified the conditional statement
376 //if (field>HZ_SIM_PARAMETERS && !result)
377 if (field>HZ_SIM_PARAMETERS && (result == 0x80FF))
378 //end 30439
379 {
380 hzIndex = field - HZ_SIM_CELL_CACHE;
381 simFile = data->buffer2;
382 fileIndex = 0;
383
384 homezone[hzIndex].lac[record-1] = readHexFromSimfile(&simFile[fileIndex],2);
385 fileIndex+=2;
386 homezone[hzIndex].cid[record-1] = readHexFromSimfile(&simFile[fileIndex],2);
387
388 #ifdef TRACE_MMIHOMEZONE
389 TRACE_EVENT_P2("read lac = %x, cid = %x", homezone[hzIndex].lac[record-1], homezone[hzIndex].cid[record-1]);
390 #endif
391 }
392
393 /* Read in the next record */
394
395 keepLooking = TRUE;
396
397 while (keepLooking)
398 {
399 /* check SIM read result for hoemzone cache */
400 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
401 //begin 30439
402 //Modified the conditional statement
403 //if (record==HZ_CACHE_MAX || result)
404 if (record==HZ_CACHE_MAX || (result != 0x80FF))
405 //end 30439
406 {
407 field++; // Look at next field
408 record = 1;
409 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
410 // Print the current feild.
411 TRACE_EVENT_P1("current field = %x", field);
412 }
413 else
414 record++;
415
416 hzIndex = field-HZ_SIM_CELL_CACHE;
417
418 if (hzIndex==HZ_ZONES_MAX)
419 {
420 keepLooking = FALSE;
421 /* Have read all sim data, set flag so icon etc will be updated */
422 data->received |= HZ_RECEIVED_SIMDATA;
423 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
424 //begin 30439
425 /* homezone display update after SIM REFRESH (when hzFlag set to 1) */
426 TRACE_EVENT_P1("hzFlag = %d", hzFlag);
427 if (hzFlag)
428 {
429 // hzFlag = 0;
430 homezoneUpdate(0, 0, 1);
431 }
432 else
433 {
434
435 TRACE_EVENT("activate homezone CB");
436 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
437 //Call to activate the Homezone CB.
438 Activate_cb = 1;
439 sms_homezoneCBToggle(Activate_cb);
440 homezoneUpdate(0, 0, 1); /* new VO : speed up update */
441 }
442 //end 30439
443
444 }
445 else if (homezone[hzIndex].active)
446 {
447 keepLooking = FALSE;
448
449 #ifdef TRACE_MMIHOMEZONE
450 //TRACE_EVENT_P3("HZ READ HZ %d field %X record %d", hzIndex, field, record);
451 #endif
452 if (!Read_Sim_Record(field, record, HZ_SIM_CELL_CACHE_SIZE, data->buffer2))
453 {
454 TRACE_EVENT("SIM reading error!");
455 }
456 }
457 }
458
459 return;
460 }
461
462
463 /*******************************************************************************
464
465 $Function: homezoneReadParams
466
467 $Description: Decode the homezone parameters from the first SIM field
468
469 $Returns: None.
470
471 $Arguments: None.
472 *******************************************************************************/
473
474 void homezoneReadParams()
475 {
476 T_homezone_data *data = &homezoneData;
477 T_homezone *homezone = data->homezone;
478 UBYTE *simFile;
479 USHORT fileIndex;
480 USHORT tagIndex;
481 USHORT hzIndex;
482 char character;
483
484 TRACE_FUNCTION("homezoneReadParams()");
485
486 simFile = data->buffer;
487 fileIndex = HZ_SIM_FIRST_ZONE; // Point to the first homezone data
488
489 for (hzIndex=0; hzIndex<HZ_ZONES_MAX; hzIndex++) // For each homezone...
490 {
491 homezone[hzIndex].zoneID = simFile[fileIndex]; // Read in the various parameters
492 fileIndex++;
493
494 homezone[hzIndex].X = readHexFromSimfile(&simFile[fileIndex],4);
495 fileIndex += 4;
496 homezone[hzIndex].Y = readHexFromSimfile(&simFile[fileIndex],4);
497 fileIndex += 4;
498 homezone[hzIndex].Rsquared = readHexFromSimfile(&simFile[fileIndex],4);
499 fileIndex += 4;
500
501 homezone[hzIndex].active = (BOOL) (simFile[fileIndex] & HZ_ACTIVE_FLAG)/HZ_ACTIVE_FLAG;
502 homezone[hzIndex].cityzone = (BOOL) (simFile[fileIndex] & HZ_CITYZONE_FLAG)/HZ_CITYZONE_FLAG;
503 fileIndex++;
504
505 /* Read in the 12-character tag name */
506
507 for (tagIndex = 0; tagIndex<HZ_NAME_LENGTH; tagIndex++)
508 {
509 character = (char) simFile[fileIndex];
510 fileIndex++;
511 if (character<32 || character>127)
512 character = 0;
513 homezone[hzIndex].Tag[tagIndex] = character;
514 }
515 homezone[hzIndex].Tag[HZ_NAME_LENGTH] = 0; // Make sure tag is null-terminated
516
517 #ifdef TRACE_MMIHOMEZONE
518 TRACE_EVENT_P1("Homezone %d:", hzIndex);
519 TRACE_EVENT_P1("ID: %d", homezone[hzIndex].zoneID);
520 TRACE_EVENT_P1("Active: %d", (UBYTE)homezone[hzIndex].active);
521 TRACE_EVENT_P1("Cityzone: %d", (UBYTE)homezone[hzIndex].cityzone);
522 TRACE_EVENT_P1("X: %X", homezone[hzIndex].X);
523 TRACE_EVENT_P1("Y: %X", homezone[hzIndex].Y);
524 TRACE_EVENT_P1("Rsquared: %X", homezone[hzIndex].Rsquared);
525 TRACE_EVENT_P1("Homezone name: %s", homezone[hzIndex].Tag);
526 #endif
527
528 }
529
530 return;
531 }
532
533
534 /*******************************************************************************
535
536 $Function: homezoneWriteSim
537
538 $Description: Write homezone data to the SIM
539 SPR 877 - SH - now just writes a single record
540
541 $Returns: None.
542
543 $Arguments: cache, record
544 ********************************************************************************/
545
546 void homezoneWriteSim(USHORT field, USHORT record)
547 {
548 T_homezone_data *data = &homezoneData;
549 USHORT hzIndex;
550 UBYTE *simFile;
551 USHORT fileIndex;
552
553 /* Check if homezone is already switched off */
554
555 if (data->received==HZ_RECEIVED_HZ_OFF)
556 return;
557
558 TRACE_FUNCTION("homezoneWriteSim()");
559
560 hzIndex = field-HZ_SIM_CELL_CACHE;
561
562 #ifdef TRACE_MMIHOMEZONE
563 TRACE_EVENT_P4("HZ WRITE field: %X record %d lac %X cid %X", field, record, data->homezone[hzIndex].lac[record-1], data->homezone[hzIndex].cid[record-1]);
564 #endif
565
566 if (data->homezone[hzIndex].active)
567 {
568 simFile = data->buffer2;
569 fileIndex = 0;
570 writeHexToSimfile(&simFile[fileIndex], data->homezone[hzIndex].lac[record-1], 2 );
571 fileIndex += 2;
572 writeHexToSimfile(&simFile[fileIndex], data->homezone[hzIndex].cid[record-1], 2 );
573 }
574
575 if (!Write_Sim_Record(field, record, HZ_SIM_CELL_CACHE_SIZE, data->buffer2))
576 {
577 TRACE_EVENT("SIM writing error!");
578 }
579 return;
580 }
581
582
583 /*******************************************************************************
584
585 $Function: homezoneWriteSimCb
586
587 $Description: Write homezone data to the SIM. This function is called after a previous
588 SIM write (or, in the initial case, by homezoneWriteSim above).
589 SPR877 - SH - Previous functionality no longer required here.
590
591 $Returns: None.
592
593 $Arguments: field - the SIM field that is to be written
594 record - the SIM record that is to be written
595 result - the result of the last write attempt
596 *******************************************************************************/
597
598 void homezoneWriteSimCb(USHORT field, USHORT record, USHORT result)
599 {
600 T_homezone_data *data = &homezoneData;
601 T_homezone *homezone = data->homezone;
602 USHORT hzIndex;
603 UBYTE *simFile;
604 USHORT fileIndex;
605 UBYTE keepLooking;
606
607 TRACE_FUNCTION("homezoneWriteSimCb()");
608
609 #ifdef TRACE_MMIHOMEZONE
610 TRACE_EVENT_P1("RESULT: %d", result);
611 #endif
612
613 return;
614 }
615
616
617 /*******************************************************************************
618
619 $Function: homezoneCBData
620
621 $Description: Make sure correct homezone CB channel is set up and activate CB
622
623 $Returns: None.
624
625 $Arguments: message - The text of the cell broadcast message
626 *******************************************************************************/
627
628 void homezoneActivateCB(void)
629 {
630 T_homezone_data *data = &homezoneData;
631 USHORT index;
632 UBYTE stopSearch;
633 USHORT emptyID;
634
635 /* Check if homezone is already switched off */
636
637 if (data->received==HZ_RECEIVED_HZ_OFF)
638 return;
639
640 TRACE_FUNCTION("homezoneActivateCB()");
641
642 /* Check table to see if correct channel is included */
643
644 stopSearch = FALSE;
645 emptyID = 0xFFFF;
646
647 for (index=0; index<MAX_MIDS && !stopSearch; index++)
648 {
649 TRACE_EVENT_P2("Mid %d is %X", index, g_smscb_data.CBTopics.entry[index].msg_id);
650 if (g_smscb_data.CBTopics.entry[index].msg_id==HZ_IDENTIFIER)
651 {
652 stopSearch = TRUE;
653 }
654 else if (g_smscb_data.CBTopics.entry[index].msg_id==NO_MID)
655 {
656 emptyID = index;
657 stopSearch = TRUE;
658 }
659 }
660
661 TRACE_EVENT_P1("Emtpy ID %d", emptyID);
662
663 if (emptyID!=0xFFFF && emptyID<MAX_MIDS-1)
664 {
665 strncpy (g_smscb_data.CBTopics.entry[emptyID].name, HZ_CB_NAME, CB_TAG_LENGTH);
666 g_smscb_data.CBTopics.entry[emptyID].msg_id = HZ_IDENTIFIER;
667 g_smscb_data.CBTopics.entry[emptyID].dcs = 0;
668
669 // add a new entry
670 emptyID += 1;
671 g_smscb_data.CBTopics.length = emptyID;
672 }
673
674 smscb_setCBsettings(SMSCB_SWITCH_ON);
675 return;
676 }
677
678
679 /*******************************************************************************
680
681 $Function: homezoneCBData
682
683 $Description: A cell broadcast message has been received, containing information about
684 the location of the current cell
685
686 $Returns: None.
687
688 $Arguments: message - The text of the cell broadcast message
689 *******************************************************************************/
690
691 void homezoneCBData(char *message)
692 {
693 T_homezone_data *data = &homezoneData;
694
695 /* Check if homezone is already switched off */
696
697 if (data->received==HZ_RECEIVED_HZ_OFF)
698 return;
699
700 TRACE_FUNCTION("homezoneCellData()");
701
702 /* Calculate the current position from the text of the message */
703
704 data->current_X = calculateDecimal( &message[0], HZ_COORD_DIGITS );
705 data->current_Y = calculateDecimal( &message[HZ_COORD_DIGITS], HZ_COORD_DIGITS );
706
707 #ifdef TRACE_MMIHOMEZONE
708 TRACE_EVENT_P2("current_X: %X, current_Y: %X", data->current_X, data->current_Y);
709 #endif
710
711 data->received |= HZ_RECEIVED_CB; // We now have received cell broadcast message.
712
713 /* SPR877 - SH - now only call HZ algorithm if a cell res has recently taken place */
714
715 if (data->received==HZ_RECEIVED_ALL && data->new_cell_res) // If we've received everything, call algorithm.
716 {
717 homezoneLocate();
718 data->new_cell_res = FALSE;
719 }
720
721 return;
722 }
723
724
725 /*******************************************************************************
726
727 $Function: homezoneLocate
728
729 $Description: Looks at coordinates from cell broadcast message and calculates if
730 they are in a homezone
731
732 $Returns: None
733
734 $Arguments: None
735
736 *******************************************************************************/
737
738 void homezoneLocate()
739 {
740 T_homezone_data *data = &homezoneData;
741 T_homezone *homezone = data->homezone;
742 long deltaX;
743 long deltaY;
744 USHORT hzIndex;
745 USHORT cacheIndex;
746 U32 Dsquared;
747 BOOL foundInCache;
748 USHORT cacheFreeSpace;
749 USHORT field;
750 USHORT record;
751 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
752 //begin 30439
753 UBYTE version;
754 USHORT max_rcd;
755 EF_HZCACHE cache;
756 UBYTE exist = 0;
757 //end 30439
758
759 /* Check if homezone is already switched off */
760
761 if (data->received==HZ_RECEIVED_HZ_OFF)
762 return;
763
764 TRACE_FUNCTION("homezoneLocate()");
765
766 data->current_zone = HZ_NOT_IN_ZONE; // We don't know if we're in a homezone yet (homezones = 0 to 3)
767 field = HZ_NOT_IN_ZONE; // The cache to update
768
769 /* Work out if we're in a homezone using current_X and current_Y, received from CB message */
770
771 if (data->received == HZ_RECEIVED_ALL)
772 {
773 #ifdef TRACE_MMIHOMEZONE
774 TRACE_EVENT_P2("Current cell X: %X, Y: %X", data->current_X,data->current_Y);
775 #endif
776
777 /* Check to see if (current_X,current_Y) is in any of the defined homezones */
778
779 for (hzIndex=0; hzIndex<HZ_ZONES_MAX && data->current_zone==HZ_NOT_IN_ZONE; hzIndex++) // For each homezone...
780 {
781 #ifdef TRACE_MMIHOMEZONE
782 TRACE_EVENT_P1("Homezone %d...", hzIndex);
783 TRACE_EVENT_P3("Has coords X: %X, Y: %X, R2: %X", homezone[hzIndex].X, homezone[hzIndex].Y, homezone[hzIndex].Rsquared);
784 #endif
785
786 if (homezone[hzIndex].active) // Provided the homezone is active
787 {
788 #ifdef TRACE_MMIHOMEZONE // Calculate X and Y distance
789 TRACE_EVENT("Is active.");
790 #endif
791 deltaX = labs(data->current_X-homezone[hzIndex].X); // between centre of current cell
792 deltaY = labs(data->current_Y-homezone[hzIndex].Y); // and centre of the homezone
793 #ifdef TRACE_MMIHOMEZONE
794 TRACE_EVENT_P1("deltaX = %d",deltaX);
795 TRACE_EVENT_P1("deltaY = %d",deltaY);
796 #endif
797 if (deltaX<=HZ_DISTANCE_MAX && deltaY<=HZ_DISTANCE_MAX) // If not too far...
798 {
799 Dsquared = deltaX*deltaX+deltaY*deltaY; // Calculate the resultant distance squared
800 #ifdef TRACE_MMIHOMEZONE
801 TRACE_EVENT_P1("Dsquared = %d",Dsquared);
802 #endif
803 if (Dsquared <= homezone[hzIndex].Rsquared) // If within radius of homezone squared
804 {
805 #ifdef TRACE_MMIHOMEZONE
806 TRACE_EVENT("Contains the current cell.");
807 #endif
808 data->current_zone = hzIndex; // Current zone is this homezone
809
810 if (!homezone[hzIndex].cityzone) // Then: if it's not a cityzone
811 {
812 #ifdef TRACE_MMIHOMEZONE
813 TRACE_EVENT("Is not a cityzone.");
814 #endif
815 foundInCache = FALSE; // Look through the cache for this
816 cacheFreeSpace = HZ_CACHE_MAX; // homezone to see if cell is listed
817
818 for (cacheIndex=0; cacheIndex<HZ_CACHE_MAX && !foundInCache; cacheIndex++)
819 {
820 if (data->cid==homezone[hzIndex].cid[cacheIndex])
821 {
822 foundInCache = TRUE; // We've found it!
823 }
824 if (homezone[hzIndex].cid[cacheIndex]==0 && cacheFreeSpace==HZ_CACHE_MAX)
825 cacheFreeSpace = cacheIndex; // Or we've found an empty space
826 }
827
828 if (!foundInCache) // If not there, need to add it
829 {
830 #ifdef TRACE_MMIHOMEZONE
831 TRACE_EVENT("Is not in the cache.");
832 #endif
833 if (cacheFreeSpace==HZ_CACHE_MAX) // If we didn't find a free space...
834 {
835 cacheFreeSpace = rand() % HZ_CACHE_MAX; // Choose a random entry
836 }
837 homezone[hzIndex].cid[cacheFreeSpace] = data->cid; // And store current cell there
838 homezone[hzIndex].lac[cacheFreeSpace] = data->lac; // with its location area code
839
840 field = hzIndex+HZ_SIM_CELL_CACHE; // We've changed the cache
841 record = cacheFreeSpace+1;
842
843 #ifdef TRACE_MMIHOMEZONE
844 TRACE_EVENT_P1("Have added to cache, entry %d.",cacheFreeSpace);
845 #endif
846 }
847 }
848 }
849 else // If we're not in the homezone...
850 {
851 foundInCache = FALSE; // Look through the cache for this
852 // homezone to see if cell is listed
853 for (cacheIndex=0; cacheIndex<HZ_CACHE_MAX && !foundInCache; cacheIndex++)
854 {
855 if (data->cid==homezone[hzIndex].cid[cacheIndex])
856 {
857 foundInCache = TRUE; // We've found it!
858 cacheFreeSpace = cacheIndex; // Record where it is
859 break;
860 }
861 }
862
863 if (foundInCache) // If it's there...
864 {
865 #ifdef TRACE_MMIHOMEZONE
866 TRACE_EVENT("Is in the cache and shouldn't be.");
867 #endif
868 homezone[hzIndex].cid[cacheFreeSpace] = 0; // ...remove it
869 field = hzIndex+HZ_SIM_CELL_CACHE; // We've changed the cache
870 record = cacheFreeSpace+1;
871 data->current_zone = HZ_NOT_IN_ZONE; // We're not in this zone
872 }
873 #ifdef TRACE_MMIHOMEZONE
874 else
875 {
876 TRACE_EVENT("Isn't in the cache and shouldn't be.");
877 }
878 #endif
879 }
880
881 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
882 //begin 30439
883 /* check if the cid is already in cache */
884 for (cacheIndex=0; cacheIndex<HZ_CACHE_MAX; cacheIndex++)
885 {
886 if (data->recent_cell[cacheIndex] == data->cid)
887 exist = 1;
888 }
889 /* Replace oldest cell in dynamic cache with new cell */
890 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
891 //begin 30439
892 //Added a conditional statement
893 if (!exist)
894 {
895 data->recent_cell_index++;
896 if (data->recent_cell_index>=HZ_RECENT_MAX)
897 data->recent_cell_index = 0;
898 #ifdef TRACE_MMIHOMEZONE
899 TRACE_EVENT_P1("Adding to recent list, index = %d", data->recent_cell_index);
900 #endif
901 data->recent_cell[data->recent_cell_index] = data->cid;
902 data->recent_cell_zone[data->recent_cell_index] = data->current_zone;
903
904 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
905 //begin 30439
906 /* write cache to PCM */
907 writeHexToSimfile(&cache.cid[0], data->recent_cell[data->recent_cell_index], 2 );
908 cache.zone = data->recent_cell_zone[data->recent_cell_index];
909 /* write cache to PCM */
910 pcm_WriteRecord((UBYTE *)EF_HZCACHE_ID,
911 (USHORT)(data->recent_cell_index+1),
912 SIZE_EF_HZCACHE,
913 &cache.cid[0]);
914
915 }
916 //end 30439
917 #ifdef TRACE_MMIHOMEZONE
918 for (cacheIndex = 0; cacheIndex<HZ_RECENT_MAX; cacheIndex++)
919 {
920 TRACE_EVENT_P3("Recent cache %d: CID %X, zone %X",cacheIndex, data->recent_cell[cacheIndex], data->recent_cell_zone[cacheIndex]);
921 }
922 #endif
923 }
924
925 }
926
927 }
928
929 }
930
931 #ifdef TRACE_MMIHOMEZONE
932 TRACE_EVENT("CACHES AFTER UPDATE");
933 for (hzIndex=0; hzIndex<HZ_ZONES_MAX; hzIndex++) // For each homezone...
934 {
935 TRACE_EVENT_P2("Zone %d (%s)", hzIndex, homezone[hzIndex].Tag);
936
937 if (homezone[hzIndex].active && !homezone[hzIndex].cityzone) // If it's active, and not a cityzone
938 {
939 for (cacheIndex=0; cacheIndex<HZ_CACHE_MAX; cacheIndex++) // Check the cache.
940 {
941 TRACE_EVENT_P3("Cache %d: lac %X, cid %X", cacheIndex, homezone[hzIndex].lac[cacheIndex], homezone[hzIndex].cid[cacheIndex]);
942 }
943 }
944 }
945 #endif
946 /* Update icon/text tag. */
947
948 homezoneUpdateDisplay();
949
950 /* Write data back to SIM if cache has changed & SIM files present */
951
952 if (field!=HZ_NOT_IN_ZONE && (data->received & HZ_RECEIVED_SIMDATA))
953 {
954 homezoneWriteSim(field, record);
955 }
956
957 return;
958 }
959
960
961 /*******************************************************************************
962
963 $Function: homezoneUpdate
964
965 $Description: Main homezone function; check whether MS is in a homezone or not
966
967 $Returns:
968
969 $Arguments: lac - the location area code of the current cell (on cell reselection)
970 cid - the ID of the current cell (on cell reselection)
971 keep - 1: no change in lac and cid
972 *******************************************************************************/
973 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
974 //begin 30439
975 //Added an extra argument in the function -- "keep"
976 void homezoneUpdate(USHORT lac, USHORT cid, UBYTE keep)
977 {
978 T_homezone_data *data = &homezoneData;
979 T_homezone *homezone = data->homezone;
980 USHORT hzIndex;
981 USHORT cacheIndex;
982 UBYTE cacheUpdate;
983 UBYTE recordUpdate;
984 UBYTE inCache = 0;
985
986 /* Check if homezone is already switched off */
987
988 TRACE_EVENT_P1("Data received: %d", data->received);
989
990 if (data->received==HZ_RECEIVED_HZ_OFF)
991 return;
992
993 TRACE_FUNCTION("homezoneUpdate()");
994
995 data->current_zone = HZ_NOT_IN_ZONE; // We don't know if we're in a homezone yet (homezones = 0 to 3)
996 data->received |= HZ_RECEIVED_CELLRES; // Have received this event
997 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
998 //Modified to add a conditional statement
999 //begin 30439
1000 if (!keep)
1001 {
1002 data->lac = lac;
1003 data->cid = cid;
1004 }
1005 /* keep the current lac and cid */
1006 else
1007 {
1008 lac = data->lac;
1009 cid = data->cid;
1010 }
1011 //end 30439
1012
1013 #ifdef TRACE_MMIHOMEZONE
1014 TRACE_EVENT_P3("lac: %X, cid: %X, received: %d", lac, cid, data->received);
1015 #endif
1016
1017 /* If either are zero or -1, the reselection data is invalid */
1018 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
1019 //Modified to add a conditional statement
1020 if (((lac==0 || cid==0) || (lac==0xFFFF || cid==0xFFFF)) AND !keep)
1021 {
1022 TRACE_EVENT_P1("homezoneUpdateDisplay ~HZ_RECEIVED_CELLRES keep=%d", keep);
1023 //end 30439
1024 data->received &= (~HZ_RECEIVED_CELLRES);
1025 homezoneUpdateDisplay();
1026 return;
1027 }
1028
1029 data->new_cell_res = TRUE; // Cell res just occurred
1030
1031 /* Must have received SIM data to continue*/
1032
1033 if (!(data->received & HZ_RECEIVED_SIMDATA))
1034 return;
1035
1036 /* Check homezone cache for each homezone */
1037 /* Can do this even if we haven't received the CB message */
1038
1039 #ifdef TRACE_MMIHOMEZONE
1040 TRACE_EVENT("Checking zone caches...");
1041 #endif
1042
1043 for (hzIndex=0; hzIndex<HZ_ZONES_MAX && data->current_zone==HZ_NOT_IN_ZONE; hzIndex++) // For each homezone...
1044 {
1045 #ifdef TRACE_MMIHOMEZONE
1046 TRACE_EVENT_P2("Zone %d (%s)", hzIndex, homezone[hzIndex].Tag);
1047 #endif
1048
1049 if (homezone[hzIndex].active && !homezone[hzIndex].cityzone) // If it's active, and not a cityzone
1050 {
1051 #ifdef TRACE_MMIHOMEZONE
1052 TRACE_EVENT("Is Active.");
1053 #endif
1054 for (cacheIndex=0; cacheIndex<HZ_CACHE_MAX && data->current_zone==HZ_NOT_IN_ZONE; cacheIndex++) // Check the cache.
1055 {
1056 #ifdef TRACE_MMIHOMEZONE
1057 TRACE_EVENT_P3("Cache %d: lac %X, cid %X", cacheIndex, homezone[hzIndex].lac[cacheIndex], homezone[hzIndex].cid[cacheIndex]);
1058 #endif
1059
1060 if (cid==homezone[hzIndex].cid[cacheIndex]) // If the current cell is in the cache....
1061 {
1062 #ifdef TRACE_MMIHOMEZONE
1063 TRACE_EVENT_P1("Cell found in cache %d.",cacheIndex);
1064 #endif
1065 data->current_zone = hzIndex; // Then this is our current homezone!
1066 inCache = 1;
1067 }
1068 }
1069 if (!inCache AND hzFlag)
1070 {
1071 hzFlag = 0;
1072 TRACE_EVENT ("not in cache, caculate needed");
1073 homezoneLocate();
1074 return;
1075 }
1076 else
1077 inCache = 0;
1078 }
1079 }
1080 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
1081 //added a conditional statement
1082 //begin 30439
1083 /* If we didn't find a homezone, check recent cells cache to see if we're in a cityzone */
1084 for (hzIndex=0; hzIndex<HZ_ZONES_MAX && data->current_zone==HZ_NOT_IN_ZONE; hzIndex++) // For each homezone...
1085 {
1086 #ifdef TRACE_MMIHOMEZONE
1087 TRACE_EVENT_P2("Zone %d (%s)", hzIndex, homezone[hzIndex].Tag);
1088 #endif
1089
1090 if (homezone[hzIndex].active && homezone[hzIndex].cityzone) // If it's active, and not a cityzone
1091 {
1092 #ifdef TRACE_MMIHOMEZONE
1093 TRACE_EVENT("Is Active.");
1094 #endif
1095
1096 for (cacheIndex=0; cacheIndex<HZ_RECENT_MAX && data->current_zone==HZ_NOT_IN_ZONE; cacheIndex++) // Check the cache.
1097 {
1098 #ifdef TRACE_MMIHOMEZONE
1099 TRACE_EVENT_P5("Cache %d: lac %X, cid %X, data->recent_cell %X, data->recent_cell_zone %d", cacheIndex, homezone[hzIndex].lac[cacheIndex], homezone[hzIndex].cid[cacheIndex], data->recent_cell[cacheIndex], data->recent_cell_zone[cacheIndex]);
1100 #endif
1101
1102 if (cid==data->recent_cell[cacheIndex] && data->recent_cell_zone[cacheIndex]!=HZ_NOT_IN_ZONE) // If we're in that cell
1103 {
1104 #ifdef TRACE_MMIHOMEZONE
1105 TRACE_EVENT_P1("FOUND cityzone in cache %d.",cacheIndex);
1106 #endif
1107 //Jun 14, 2005 REF: MMI-FIX-30439 x0018858
1108 //Modified to directly assign value
1109 data->current_zone = hzIndex; // Then this is our current homezone!
1110 inCache = 1;
1111 }
1112 if (!inCache AND hzFlag)
1113 {
1114 hzFlag = 0;
1115 TRACE_EVENT ("not in cache, caculate needed");
1116 homezoneLocate();
1117 return;
1118 }
1119 else
1120 inCache = 0;
1121 }
1122 }
1123 }
1124
1125 homezoneUpdateDisplay(); // Update icon/text tag.
1126
1127 return;
1128 }
1129
1130
1131 /*******************************************************************************
1132
1133 $Function: homezoneUpdateDisplay
1134
1135 $Description:
1136
1137 $Returns: Updates the homezone icon and text string appropriately
1138
1139 $Arguments: none
1140 *******************************************************************************/
1141
1142 void homezoneUpdateDisplay(void)
1143 {
1144 T_homezone_data *data = &homezoneData;
1145
1146 TRACE_FUNCTION("homezoneUpdateDisplay()");
1147
1148 iconsDeleteState(iconIdHomezone);
1149
1150 #ifdef FF_MMI_SAT_ICON
1151 addSatMessage(NULL, 0, 0, NULL, FALSE, SAT_ICON_NONE);
1152 #else
1153 addSatMessage(NULL);
1154 #endif
1155
1156 if (data->current_zone!=HZ_NOT_IN_ZONE) // If not in a homezone, leave blank
1157 {
1158 //x0035544 Mar 14, 2006 DR:OMAPS00061468
1159 #ifdef FF_MMI_SAT_ICON
1160 addSatMessage(data->homezone[data->current_zone].Tag, 0, 0, NULL, FALSE, SAT_ICON_NONE);
1161 #else
1162 addSatMessage(data->homezone[data->current_zone].Tag);
1163 #endif
1164 if (!data->homezone[data->current_zone].cityzone) // Display icon if homezone rather than cityzone
1165 {
1166 iconsSetState(iconIdHomezone);
1167 }
1168 }
1169
1170 return;
1171 }
1172
1173
1174 /*******************************************************************************
1175
1176 $Function: calculateDecimal
1177
1178 $Description:
1179
1180 $Returns: Returns a decimal number from a string of ascii digits
1181
1182 $Arguments: none
1183 *******************************************************************************/
1184
1185 static U32 calculateDecimal( char *string, int length )
1186 {
1187 U32 total = 0;
1188 int index;
1189
1190 /* decode each decimal character in turn */
1191 for (index = 0; index < length; index++ )
1192 {
1193 if (string[index]>='0' && string[index]<='9')
1194 {
1195 total = ( total * 10 ) + ( string[index] - '0' );
1196 }
1197 }
1198
1199 return total;
1200 }
1201
1202 /*******************************************************************************
1203
1204 $Function: readHexFromSimfile
1205
1206 $Description: Reads a hex string (MSB first) from a sim file
1207
1208 $Returns: The hex number
1209
1210 $Arguments: simFile - the point in the simFile at which the string occurs
1211 length - the length of the string
1212 *******************************************************************************/
1213
1214 static U32 readHexFromSimfile( UBYTE *simFile, int length )
1215 {
1216 U32 total = 0;
1217 int index;
1218
1219 for ( index = 0; index < length; index++ )
1220 {
1221 total = ( total << 8 ) + simFile[index];
1222 }
1223
1224 return total;
1225 }
1226
1227 /*******************************************************************************
1228
1229 $Function: writeHexToSimfile
1230
1231 $Description: Writes a hex string (MSB first) to a sim file
1232
1233 $Returns: None
1234
1235 $Arguments: simFile - the point in the simFile at which the string occurs
1236 length - the length of the string
1237 *******************************************************************************/
1238
1239 static void writeHexToSimfile( UBYTE *simFile, U32 value, int length )
1240 {
1241 int index;
1242
1243 #ifdef TRACE_MMIHOMEZONE
1244 TRACE_EVENT_P1("Hex of %X is:", value);
1245 #endif
1246
1247 /* Note: '-1' below clarification:
1248 * E.g. index=0, length=4: most significant byte is number shifted 3 bytes right. */
1249
1250 for ( index = 0; index < length; index++ )
1251 {
1252 simFile[index] = (value >> ((length-index-1)*8)) & 0xFF; /* SPR877 - SH - wrong before, added *8 */
1253 #ifdef TRACE_MMIHOMEZONE
1254 TRACE_EVENT_P2("Simfile %d is %X", index, simFile[index]);
1255 #endif
1256 }
1257
1258 return;
1259 }