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