OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2004-2008 Atheros Communications Inc. |
| 3 * All rights reserved. |
| 4 * |
| 5 * This file implements the Atheros PS and patch parser. |
| 6 * It implements APIs to parse data buffer with patch and PS information and con
vert it to HCI commands. |
| 7 * |
| 8 * |
| 9 * |
| 10 * ar3kpsparser.c |
| 11 * |
| 12 * |
| 13 * |
| 14 * The software source and binaries included in this development package are |
| 15 * licensed, not sold. You, or your company, received the package under one |
| 16 * or more license agreements. The rights granted to you are specifically |
| 17 * listed in these license agreement(s). All other rights remain with Atheros |
| 18 * Communications, Inc., its subsidiaries, or the respective owner including |
| 19 * those listed on the included copyright notices.. Distribution of any |
| 20 * portion of this package must be in strict compliance with the license |
| 21 * agreement(s) terms. |
| 22 * |
| 23 * |
| 24 * |
| 25 */ |
| 26 |
| 27 |
| 28 #include "ar3kpsparser.h" |
| 29 |
| 30 #define BD_ADDR_SIZE 6 |
| 31 #define WRITE_PATCH 8 |
| 32 #define ENABLE_PATCH 11 |
| 33 #define PS_RESET 2 |
| 34 #define PS_WRITE 1 |
| 35 #define PS_VERIFY_CRC 9 |
| 36 #define CHANGE_BDADDR 15 |
| 37 |
| 38 #define HCI_COMMAND_HEADER 7 |
| 39 |
| 40 #define HCI_EVENT_SIZE 7 |
| 41 |
| 42 #define WRITE_PATCH_COMMAND_STATUS_OFFSET 5 |
| 43 |
| 44 #define RAM_PS_REGION (1<<0) |
| 45 #define RAM_PATCH_REGION (1<<1) |
| 46 #define RAMPS_MAX_PS_DATA_PER_TAG 20000 |
| 47 #define MAX_RADIO_CFG_TABLE_SIZE 244 |
| 48 #define RAMPS_MAX_PS_TAGS_PER_FILE 50 |
| 49 |
| 50 #define PS_MAX_LEN 500 |
| 51 #define LINE_SIZE_MAX (PS_MAX_LEN *2) |
| 52 |
| 53 /* Constant values used by parser */ |
| 54 #define BYTES_OF_PS_DATA_PER_LINE 16 |
| 55 #define RAMPS_MAX_PS_DATA_PER_TAG 20000 |
| 56 |
| 57 |
| 58 /* Number pf PS/Patch entries in an HCI packet */ |
| 59 #define MAX_BYTE_LENGTH 244 |
| 60 |
| 61 #define SKIP_BLANKS(str) while (*str == ' ') str++ |
| 62 #define MIN(x, y) (((x) <= (y))? (x):(y)) |
| 63 #define MAX(x, y) (((x) >= (y))? (x):(y)) |
| 64 |
| 65 #define UNUSED(x) (x=x) |
| 66 |
| 67 #define IS_BETWEEN(x, lower, upper) (((lower) <= (x)) && ((x) <= (upper))) |
| 68 #define IS_DIGIT(c) (IS_BETWEEN((c), '0', '9')) |
| 69 #define IS_HEX(c) (IS_BETWEEN((c), '0', '9') || IS_BETWEEN((c), 'a', 'f') || I
S_BETWEEN((c), 'A', 'F')) |
| 70 #define TO_LOWER(c) (IS_BETWEEN((c), 'A', 'Z') ? ((c) - 'A' + 'a') : (c)) |
| 71 #define IS_BLANK(c) ((c) == ' ') |
| 72 #define CONV_DEC_DIGIT_TO_VALUE(c) ((c) - '0') |
| 73 #define CONV_HEX_DIGIT_TO_VALUE(c) (IS_DIGIT(c) ? ((c) - '0') : (IS_BETWEEN((c),
'A', 'Z') ? ((c) - 'A' + 10) : ((c) - 'a' + 10))) |
| 74 #define CONV_VALUE_TO_HEX(v) ((A_UINT8)( ((v & 0x0F) <= 9) ? ((v & 0x0F) + '0')
: ((v & 0x0F) - 10 + 'A') ) ) |
| 75 |
| 76 |
| 77 enum MinBootFileFormatE |
| 78 { |
| 79 MB_FILEFORMAT_RADIOTBL, |
| 80 MB_FILEFORMAT_PATCH, |
| 81 MB_FILEFORMAT_COEXCONFIG |
| 82 }; |
| 83 |
| 84 enum RamPsSection |
| 85 { |
| 86 RAM_PS_SECTION, |
| 87 RAM_PATCH_SECTION, |
| 88 RAM_DYN_MEM_SECTION |
| 89 }; |
| 90 |
| 91 enum eType { |
| 92 eHex, |
| 93 edecimal |
| 94 }; |
| 95 |
| 96 |
| 97 typedef struct tPsTagEntry |
| 98 { |
| 99 A_UINT32 TagId; |
| 100 A_UINT32 TagLen; |
| 101 A_UINT8 *TagData; |
| 102 } tPsTagEntry, *tpPsTagEntry; |
| 103 |
| 104 typedef struct tRamPatch |
| 105 { |
| 106 A_UINT16 Len; |
| 107 A_UINT8 * Data; |
| 108 } tRamPatch, *ptRamPatch; |
| 109 |
| 110 |
| 111 |
| 112 typedef struct ST_PS_DATA_FORMAT { |
| 113 enum eType eDataType; |
| 114 A_BOOL bIsArray; |
| 115 }ST_PS_DATA_FORMAT; |
| 116 |
| 117 typedef struct ST_READ_STATUS { |
| 118 unsigned uTagID; |
| 119 unsigned uSection; |
| 120 unsigned uLineCount; |
| 121 unsigned uCharCount; |
| 122 unsigned uByteCount; |
| 123 }ST_READ_STATUS; |
| 124 |
| 125 |
| 126 /* Stores the number of PS Tags */ |
| 127 static A_UINT32 Tag_Count = 0; |
| 128 |
| 129 /* Stores the number of patch commands */ |
| 130 static A_UINT32 Patch_Count = 0; |
| 131 static A_UINT32 Total_tag_lenght = 0; |
| 132 static A_BOOL BDADDR = FALSE; |
| 133 A_UINT32 StartTagId; |
| 134 |
| 135 tPsTagEntry PsTagEntry[RAMPS_MAX_PS_TAGS_PER_FILE]; |
| 136 tRamPatch RamPatch[MAX_NUM_PATCH_ENTRY]; |
| 137 |
| 138 |
| 139 A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat
); |
| 140 char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos); |
| 141 char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_U
INT32 *pos); |
| 142 static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacke
t *PSPatchPacket,A_UINT32 *index); |
| 143 |
| 144 /* Function to reads the next character from the input buffer */ |
| 145 char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos) |
| 146 { |
| 147 char Ch; |
| 148 if(buffer == NULL || *pos >=len ) |
| 149 { |
| 150 return '\0'; |
| 151 } else { |
| 152 Ch = buffer[*pos]; |
| 153 (*pos)++; |
| 154 return Ch; |
| 155 } |
| 156 } |
| 157 /* PS parser helper function */ |
| 158 unsigned int uGetInputDataFormat(char* pCharLine, ST_PS_DATA_FORMAT *pstFormat) |
| 159 { |
| 160 if(pCharLine[0] != '[') { |
| 161 pstFormat->eDataType = eHex; |
| 162 pstFormat->bIsArray = true; |
| 163 return 0; |
| 164 } |
| 165 switch(pCharLine[1]) { |
| 166 case 'H': |
| 167 case 'h': |
| 168 if(pCharLine[2]==':') { |
| 169 if((pCharLine[3]== 'a') || (pCharLine[3]== 'A')) { |
| 170 if(pCharLine[4] == ']') { |
| 171 pstFormat->eDataType = eHex; |
| 172 pstFormat->bIsArray = true; |
| 173 pCharLine += 5; |
| 174 return 0; |
| 175 } |
| 176 else { |
| 177 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n"));
//[H:A |
| 178 return 1; |
| 179 } |
| 180 } |
| 181 if((pCharLine[3]== 'S') || (pCharLine[3]== 's')) { |
| 182 if(pCharLine[4] == ']') { |
| 183 pstFormat->eDataType = eHex; |
| 184 pstFormat->bIsArray = false; |
| 185 pCharLine += 5; |
| 186 return 0; |
| 187 } |
| 188 else { |
| 189 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n"));
//[H:A |
| 190 return 1; |
| 191 } |
| 192 } |
| 193 else if(pCharLine[3] == ']') { //[H:] |
| 194 pstFormat->eDataType = eHex; |
| 195 pstFormat->bIsArray = true; |
| 196 pCharLine += 4; |
| 197 return 0; |
| 198 } |
| 199 else { //[H: |
| 200 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); |
| 201 return 1; |
| 202 } |
| 203 } |
| 204 else if(pCharLine[2]==']') { //[H] |
| 205 pstFormat->eDataType = eHex; |
| 206 pstFormat->bIsArray = true; |
| 207 pCharLine += 3; |
| 208 return 0; |
| 209 } |
| 210 else { //[H |
| 211 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); |
| 212 return 1; |
| 213 } |
| 214 break; |
| 215 |
| 216 case 'A': |
| 217 case 'a': |
| 218 if(pCharLine[2]==':') { |
| 219 if((pCharLine[3]== 'h') || (pCharLine[3]== 'H')) { |
| 220 if(pCharLine[4] == ']') { |
| 221 pstFormat->eDataType = eHex; |
| 222 pstFormat->bIsArray = true; |
| 223 pCharLine += 5; |
| 224 return 0; |
| 225 } |
| 226 else { |
| 227 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 1\n"));
//[A:H |
| 228 return 1; |
| 229 } |
| 230 } |
| 231 else if(pCharLine[3]== ']') { //[A:] |
| 232 pstFormat->eDataType = eHex; |
| 233 pstFormat->bIsArray = true; |
| 234 pCharLine += 4; |
| 235 return 0; |
| 236 } |
| 237 else { //[A: |
| 238 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 2\n")); |
| 239 return 1; |
| 240 } |
| 241 } |
| 242 else if(pCharLine[2]==']') { //[H] |
| 243 pstFormat->eDataType = eHex; |
| 244 pstFormat->bIsArray = true; |
| 245 pCharLine += 3; |
| 246 return 0; |
| 247 } |
| 248 else { //[H |
| 249 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 3\n")); |
| 250 return 1; |
| 251 } |
| 252 break; |
| 253 |
| 254 case 'S': |
| 255 case 's': |
| 256 if(pCharLine[2]==':') { |
| 257 if((pCharLine[3]== 'h') || (pCharLine[3]== 'H')) { |
| 258 if(pCharLine[4] == ']') { |
| 259 pstFormat->eDataType = eHex; |
| 260 pstFormat->bIsArray = true; |
| 261 pCharLine += 5; |
| 262 return 0; |
| 263 } |
| 264 else { |
| 265 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 5\n"));
//[A:H |
| 266 return 1; |
| 267 } |
| 268 } |
| 269 else if(pCharLine[3]== ']') { //[A:] |
| 270 pstFormat->eDataType = eHex; |
| 271 pstFormat->bIsArray = true; |
| 272 pCharLine += 4; |
| 273 return 0; |
| 274 } |
| 275 else { //[A: |
| 276 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 6\n")); |
| 277 return 1; |
| 278 } |
| 279 } |
| 280 else if(pCharLine[2]==']') { //[H] |
| 281 pstFormat->eDataType = eHex; |
| 282 pstFormat->bIsArray = true; |
| 283 pCharLine += 3; |
| 284 return 0; |
| 285 } |
| 286 else { //[H |
| 287 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 7\n")); |
| 288 return 1; |
| 289 } |
| 290 break; |
| 291 |
| 292 default: |
| 293 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 8\n")); |
| 294 return 1; |
| 295 } |
| 296 } |
| 297 |
| 298 unsigned int uReadDataInSection(char *pCharLine, ST_PS_DATA_FORMAT stPS_DataForm
at) |
| 299 { |
| 300 char *pTokenPtr = pCharLine; |
| 301 |
| 302 if(pTokenPtr[0] == '[') { |
| 303 while(pTokenPtr[0] != ']' && pTokenPtr[0] != '\0') { |
| 304 pTokenPtr++; |
| 305 } |
| 306 if(pTokenPtr[0] == '\0') { |
| 307 return (0x0FFF); |
| 308 } |
| 309 pTokenPtr++; |
| 310 |
| 311 |
| 312 } |
| 313 if(stPS_DataFormat.eDataType == eHex) { |
| 314 if(stPS_DataFormat.bIsArray == true) { |
| 315 //Not implemented |
| 316 return (0x0FFF); |
| 317 } |
| 318 else { |
| 319 return (A_STRTOL(pTokenPtr, NULL, 16)); |
| 320 } |
| 321 } |
| 322 else { |
| 323 //Not implemented |
| 324 return (0x0FFF); |
| 325 } |
| 326 } |
| 327 A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat
) |
| 328 { |
| 329 char *Buffer; |
| 330 char *pCharLine; |
| 331 A_UINT8 TagCount; |
| 332 A_UINT16 ByteCount; |
| 333 A_UINT8 ParseSection=RAM_PS_SECTION; |
| 334 A_UINT32 pos; |
| 335 |
| 336 |
| 337 |
| 338 int uReadCount; |
| 339 ST_PS_DATA_FORMAT stPS_DataFormat; |
| 340 ST_READ_STATUS stReadStatus = {0, 0, 0,0}; |
| 341 pos = 0; |
| 342 Buffer = NULL; |
| 343 |
| 344 if (srcbuffer == NULL || srclen == 0) |
| 345 { |
| 346 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Could not open .\n")); |
| 347 return A_ERROR; |
| 348 } |
| 349 TagCount = 0; |
| 350 ByteCount = 0; |
| 351 Buffer = A_MALLOC(LINE_SIZE_MAX + 1); |
| 352 if(NULL == Buffer) { |
| 353 return A_ERROR; |
| 354 } |
| 355 if (FileFormat == MB_FILEFORMAT_PATCH) |
| 356 { |
| 357 int LineRead = 0; |
| 358 while((pCharLine = AthGetLine(Buffer, LINE_SIZE_MAX, srcbuffer,srclen,&pos
)) != NULL) |
| 359 { |
| 360 |
| 361 SKIP_BLANKS(pCharLine); |
| 362 |
| 363 // Comment line or empty line |
| 364 if ((pCharLine[0] == '/') && (pCharLine[1] == '/')) |
| 365 { |
| 366 continue; |
| 367 } |
| 368 |
| 369 if ((pCharLine[0] == '#')) { |
| 370 if (stReadStatus.uSection != 0) |
| 371 { |
| 372 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("error\n")); |
| 373 if(Buffer != NULL) { |
| 374 A_FREE(Buffer); |
| 375 } |
| 376 return A_ERROR; |
| 377 } |
| 378 else { |
| 379 stReadStatus.uSection = 1; |
| 380 continue; |
| 381 } |
| 382 } |
| 383 if ((pCharLine[0] == '/') && (pCharLine[1] == '*')) |
| 384 { |
| 385 pCharLine+=2; |
| 386 SKIP_BLANKS(pCharLine); |
| 387 |
| 388 if(!strncmp(pCharLine,"PA",2)||!strncmp(pCharLine,"Pa",2)||!strncmp(
pCharLine,"pa",2)) |
| 389 ParseSection=RAM_PATCH_SECTION; |
| 390 |
| 391 if(!strncmp(pCharLine,"DY",2)||!strncmp(pCharLine,"Dy",2)||!strncmp(
pCharLine,"dy",2)) |
| 392 ParseSection=RAM_DYN_MEM_SECTION; |
| 393 |
| 394 if(!strncmp(pCharLine,"PS",2)||!strncmp(pCharLine,"Ps",2)||!strncmp(
pCharLine,"ps",2)) |
| 395 ParseSection=RAM_PS_SECTION; |
| 396 |
| 397 LineRead = 0; |
| 398 stReadStatus.uSection = 0; |
| 399 |
| 400 continue; |
| 401 } |
| 402 |
| 403 switch(ParseSection) |
| 404 { |
| 405 case RAM_PS_SECTION: |
| 406 { |
| 407 if (stReadStatus.uSection == 1) //TagID |
| 408 { |
| 409 SKIP_BLANKS(pCharLine); |
| 410 if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { |
| 411 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail
\n")); |
| 412 if(Buffer != NULL) { |
| 413 A_FREE(Buffer); |
| 414 } |
| 415 return A_ERROR; |
| 416 } |
| 417 //pCharLine +=5; |
| 418 PsTagEntry[TagCount].TagId = uReadDataInSection(pCharLine, s
tPS_DataFormat); |
| 419 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" TAG ID %d \n",PsTagEntry[Ta
gCount].TagId)); |
| 420 |
| 421 //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("tag # %x\n", PsTagEntry[Ta
gCount].TagId); |
| 422 if (TagCount == 0) |
| 423 { |
| 424 StartTagId = PsTagEntry[TagCount].TagId; |
| 425 } |
| 426 stReadStatus.uSection = 2; |
| 427 } |
| 428 else if (stReadStatus.uSection == 2) //TagLength |
| 429 { |
| 430 |
| 431 if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { |
| 432 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail
\n")); |
| 433 if(Buffer != NULL) { |
| 434 A_FREE(Buffer); |
| 435 } |
| 436 return A_ERROR; |
| 437 } |
| 438 //pCharLine +=5; |
| 439 ByteCount = uReadDataInSection(pCharLine, stPS_DataFormat); |
| 440 |
| 441 //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("tag length %x\n", ByteCoun
t)); |
| 442 if (ByteCount > LINE_SIZE_MAX/2) |
| 443 { |
| 444 if(Buffer != NULL) { |
| 445 A_FREE(Buffer); |
| 446 } |
| 447 return A_ERROR; |
| 448 } |
| 449 PsTagEntry[TagCount].TagLen = ByteCount; |
| 450 PsTagEntry[TagCount].TagData = (A_UINT8*)A_MALLOC(ByteCount)
; |
| 451 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" TAG Length %d Tag Index %d
\n",PsTagEntry[TagCount].TagLen,TagCount)); |
| 452 stReadStatus.uSection = 3; |
| 453 stReadStatus.uLineCount = 0; |
| 454 } |
| 455 else if( stReadStatus.uSection == 3) { //Data |
| 456 |
| 457 if(stReadStatus.uLineCount == 0) { |
| 458 if(uGetInputDataFormat(pCharLine,&stPS_DataFormat)) { |
| 459 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat
Fail\n")); |
| 460 if(Buffer != NULL) { |
| 461 A_FREE(Buffer); |
| 462 } |
| 463 return A_ERROR; |
| 464 } |
| 465 //pCharLine +=5; |
| 466 } |
| 467 SKIP_BLANKS(pCharLine); |
| 468 stReadStatus.uCharCount = 0; |
| 469 if(pCharLine[stReadStatus.uCharCount] == '[') { |
| 470 while(pCharLine[stReadStatus.uCharCount] != ']' && pCharLine[stReadS
tatus.uCharCount] != '\0' ) { |
| 471 stReadStatus.uCharCount++; |
| 472 } |
| 473 if(pCharLine[stReadStatus.uCharCount] == ']' ) { |
| 474 stReadStatus.uCharCount++; |
| 475 } else { |
| 476 stReadStatus.uCharCount = 0; |
| 477 } |
| 478 } |
| 479 uReadCount = (ByteCount > BYTES_OF_PS_DATA_PER_LINE)? BYTES_
OF_PS_DATA_PER_LINE: ByteCount; |
| 480 //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" ")); |
| 481 if((stPS_DataFormat.eDataType == eHex) && stPS_DataFormat.bI
sArray == true) { |
| 482 while(uReadCount > 0) { |
| 483 PsTagEntry[TagCount].TagData[stReadStatus.uByteCount]
= |
| 484 (A_UINT8)(CONV_HEX_DIGIT_TO
_VALUE(pCharLine[stReadStatus.uCharCount]) << 4) |
| 485 | (A_UINT8)(CONV_HEX_DIGIT_
TO_VALUE(pCharLine[stReadStatus.uCharCount + 1])); |
| 486 |
| 487 PsTagEntry[TagCount].TagData[stReadStatus.uByteCount+
1] = |
| 488 (A_UINT8)(CONV_HEX_DIGIT_TO
_VALUE(pCharLine[stReadStatus.uCharCount + 3]) << 4) |
| 489 | (A_UINT8)(CONV_HEX_DIGIT_
TO_VALUE(pCharLine[stReadStatus.uCharCount + 4])); |
| 490 |
| 491 stReadStatus.uCharCount += 6; // read two bytes, plus
a space; |
| 492 stReadStatus.uByteCount += 2; |
| 493 uReadCount -= 2; |
| 494 } |
| 495 if(ByteCount > BYTES_OF_PS_DATA_PER_LINE) { |
| 496 ByteCount -= BYTES_OF_PS_DATA_PER_LINE; |
| 497 } |
| 498 else { |
| 499 ByteCount = 0; |
| 500 } |
| 501 } |
| 502 else { |
| 503 //to be implemented |
| 504 } |
| 505 |
| 506 stReadStatus.uLineCount++; |
| 507 |
| 508 if(ByteCount == 0) { |
| 509 stReadStatus.uSection = 0; |
| 510 stReadStatus.uCharCount = 0; |
| 511 stReadStatus.uLineCount = 0; |
| 512 stReadStatus.uByteCount = 0; |
| 513 } |
| 514 else { |
| 515 stReadStatus.uCharCount = 0; |
| 516 } |
| 517 |
| 518 if((stReadStatus.uSection == 0)&&(++TagCount == RAMPS_MAX_PS
_TAGS_PER_FILE)) |
| 519 { |
| 520 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("\n Buffer over flow PS Fi
le too big!!!")); |
| 521 if(Buffer != NULL) { |
| 522 A_FREE(Buffer); |
| 523 } |
| 524 return A_ERROR; |
| 525 //Sleep (3000); |
| 526 //exit(1); |
| 527 } |
| 528 |
| 529 } |
| 530 } |
| 531 |
| 532 break; |
| 533 default: |
| 534 { |
| 535 if(Buffer != NULL) { |
| 536 A_FREE(Buffer); |
| 537 } |
| 538 return A_ERROR; |
| 539 } |
| 540 break; |
| 541 } |
| 542 LineRead++; |
| 543 } |
| 544 Tag_Count = TagCount; |
| 545 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Number of Tags %d\n", Tag_Count)); |
| 546 } |
| 547 |
| 548 |
| 549 if (TagCount > RAMPS_MAX_PS_TAGS_PER_FILE) |
| 550 { |
| 551 |
| 552 if(Buffer != NULL) { |
| 553 A_FREE(Buffer); |
| 554 } |
| 555 return A_ERROR; |
| 556 } |
| 557 |
| 558 if(Buffer != NULL) { |
| 559 A_FREE(Buffer); |
| 560 } |
| 561 return A_OK; |
| 562 |
| 563 } |
| 564 |
| 565 |
| 566 |
| 567 /********************/ |
| 568 |
| 569 |
| 570 A_STATUS GetNextTwoChar(A_UCHAR *srcbuffer,A_UINT32 len, A_UINT32 *pos, char * b
uffer) |
| 571 { |
| 572 unsigned char ch; |
| 573 |
| 574 ch = AthReadChar(srcbuffer,len,pos); |
| 575 if(ch != '\0' && IS_HEX(ch)) { |
| 576 buffer[0] = ch; |
| 577 } else |
| 578 { |
| 579 return A_ERROR; |
| 580 } |
| 581 ch = AthReadChar(srcbuffer,len,pos); |
| 582 if(ch != '\0' && IS_HEX(ch)) { |
| 583 buffer[1] = ch; |
| 584 } else |
| 585 { |
| 586 return A_ERROR; |
| 587 } |
| 588 return A_OK; |
| 589 } |
| 590 |
| 591 A_STATUS AthDoParsePatch(A_UCHAR *patchbuffer, A_UINT32 patchlen) |
| 592 { |
| 593 |
| 594 char Byte[3]; |
| 595 char Line[MAX_BYTE_LENGTH + 1]; |
| 596 int ByteCount,ByteCount_Org; |
| 597 int count; |
| 598 int i,j,k; |
| 599 int data; |
| 600 A_UINT32 filepos; |
| 601 Byte[2] = '\0'; |
| 602 j = 0; |
| 603 filepos = 0; |
| 604 |
| 605 while(NULL != AthGetLine(Line,MAX_BYTE_LENGTH,patchbuffer,patchlen,&filepos)
) { |
| 606 if(strlen(Line) <= 1 || !IS_HEX(Line[0])) { |
| 607 continue; |
| 608 } else { |
| 609 break; |
| 610 } |
| 611 } |
| 612 ByteCount = A_STRTOL(Line, NULL, 16); |
| 613 ByteCount_Org = ByteCount; |
| 614 |
| 615 while(ByteCount > MAX_BYTE_LENGTH){ |
| 616 |
| 617 /* Handle case when the number of patch buffer is more than the 20K */ |
| 618 if(MAX_NUM_PATCH_ENTRY == Patch_Count) { |
| 619 for(i = 0; i < Patch_Count; i++) { |
| 620 A_FREE(RamPatch[i].Data); |
| 621 } |
| 622 return A_ERROR; |
| 623 } |
| 624 RamPatch[Patch_Count].Len= MAX_BYTE_LENGTH; |
| 625 RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(MAX_BYTE_LENGTH); |
| 626 Patch_Count ++; |
| 627 |
| 628 |
| 629 ByteCount= ByteCount - MAX_BYTE_LENGTH; |
| 630 } |
| 631 |
| 632 RamPatch[Patch_Count].Len= (ByteCount & 0xFF); |
| 633 if(ByteCount != 0) { |
| 634 RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(ByteCount); |
| 635 Patch_Count ++; |
| 636 } |
| 637 count = 0; |
| 638 while(ByteCount_Org > MAX_BYTE_LENGTH){ |
| 639 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Index [%d]\n",j)); |
| 640 for (i = 0,k=0; i < MAX_BYTE_LENGTH*2; i += 2,k++,count +=2) { |
| 641 if(GetNextTwoChar(patchbuffer,patchlen,&filepos,Byte) == A_ERROR) { |
| 642 return A_ERROR; |
| 643 } |
| 644 data = A_STRTOUL(&Byte[0], NULL, 16); |
| 645 RamPatch[j].Data[k] = (data & 0xFF); |
| 646 |
| 647 |
| 648 } |
| 649 j++; |
| 650 ByteCount_Org = ByteCount_Org - MAX_BYTE_LENGTH; |
| 651 } |
| 652 if(j == 0){ |
| 653 j++; |
| 654 } |
| 655 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Index [%d]\n",j)); |
| 656 for (k=0; k < ByteCount_Org; i += 2,k++,count+=2) { |
| 657 if(GetNextTwoChar(patchbuffer,patchlen,&filepos,Byte) == A_ERROR) { |
| 658 return A_ERROR; |
| 659 } |
| 660 data = A_STRTOUL(Byte, NULL, 16); |
| 661 RamPatch[j].Data[k] = (data & 0xFF); |
| 662 |
| 663 |
| 664 } |
| 665 return A_OK; |
| 666 } |
| 667 |
| 668 |
| 669 /********************/ |
| 670 A_STATUS AthDoParsePS(A_UCHAR *srcbuffer, A_UINT32 srclen) |
| 671 { |
| 672 A_STATUS status; |
| 673 int i; |
| 674 A_BOOL BDADDR_Present = A_ERROR; |
| 675 |
| 676 |
| 677 |
| 678 status = A_ERROR; |
| 679 |
| 680 if(NULL != srcbuffer && srclen != 0) |
| 681 { |
| 682 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("File Open Operation Successful\n")); |
| 683 |
| 684 status = AthParseFilesUnified(srcbuffer,srclen,MB_FILEFORMAT_PATCH); |
| 685 } |
| 686 |
| 687 |
| 688 |
| 689 if(Tag_Count == 0){ |
| 690 Total_tag_lenght = 10; |
| 691 |
| 692 } |
| 693 else{ |
| 694 for(i=0; i<Tag_Count; i++){ |
| 695 if(PsTagEntry[i].TagId == 1){ |
| 696 BDADDR_Present = A_OK; |
| 697 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR is prese
nt in Patch File \r\n")); |
| 698 |
| 699 } |
| 700 if(PsTagEntry[i].TagLen % 2 == 1){ |
| 701 Total_tag_lenght = Total_tag_lenght + PsTagEntry
[i].TagLen + 1; |
| 702 } |
| 703 else{ |
| 704 Total_tag_lenght = Total_tag_lenght + PsTagEntry
[i].TagLen; |
| 705 } |
| 706 |
| 707 } |
| 708 } |
| 709 |
| 710 if(Tag_Count > 0 && !BDADDR_Present){ |
| 711 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR is not present adding 10
extra bytes \r\n")); |
| 712 Total_tag_lenght=Total_tag_lenght + 10; |
| 713 } |
| 714 Total_tag_lenght = Total_tag_lenght+ 10 + (Tag_Count*4); |
| 715 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** Total Length %d\n",Total_tag_lenght)); |
| 716 |
| 717 |
| 718 return status; |
| 719 } |
| 720 char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_U
INT32 *pos) |
| 721 { |
| 722 |
| 723 int count; |
| 724 static short flag; |
| 725 char CharRead; |
| 726 count = 0; |
| 727 flag = A_ERROR; |
| 728 |
| 729 do |
| 730 { |
| 731 CharRead = AthReadChar(srcbuffer,len,pos); |
| 732 if( CharRead == '\0' ) { |
| 733 buffer[count+1] = '\0'; |
| 734 if(count == 0) { |
| 735 return NULL; |
| 736 } |
| 737 else { |
| 738 return buffer; |
| 739 } |
| 740 } |
| 741 |
| 742 if(CharRead == 13) { |
| 743 } else if(CharRead == 10) { |
| 744 buffer[count] ='\0'; |
| 745 flag = A_ERROR; |
| 746 return buffer; |
| 747 }else { |
| 748 buffer[count++] = CharRead; |
| 749 } |
| 750 |
| 751 } |
| 752 while(count < maxlen-1 && CharRead != '\0'); |
| 753 buffer[count] = '\0'; |
| 754 |
| 755 return buffer; |
| 756 } |
| 757 |
| 758 static void LoadHeader(A_UCHAR *HCI_PS_Command,A_UCHAR opcode,int length,int ind
ex){ |
| 759 |
| 760 HCI_PS_Command[0]= 0x0B; |
| 761 HCI_PS_Command[1]= 0xFC; |
| 762 HCI_PS_Command[2]= length + 4; |
| 763 HCI_PS_Command[3]= opcode; |
| 764 HCI_PS_Command[4]= (index & 0xFF); |
| 765 HCI_PS_Command[5]= ((index>>8) & 0xFF); |
| 766 HCI_PS_Command[6]= length; |
| 767 } |
| 768 |
| 769 ///////////////////////// |
| 770 // |
| 771 int AthCreateCommandList(PSCmdPacket **HciPacketList, A_UINT32 *numPackets) |
| 772 { |
| 773 |
| 774 A_UINT8 count; |
| 775 A_UINT32 NumcmdEntry = 0; |
| 776 |
| 777 A_UINT32 Crc = 0; |
| 778 *numPackets = 0; |
| 779 |
| 780 |
| 781 if(Patch_Count > 0) |
| 782 Crc |= RAM_PATCH_REGION; |
| 783 if(Tag_Count > 0) |
| 784 Crc |= RAM_PS_REGION; |
| 785 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("PS Thread Started CRC %x Patch Count %d Tag
Count %d \n",Crc,Patch_Count,Tag_Count)); |
| 786 |
| 787 if(Patch_Count || Tag_Count ){ |
| 788 NumcmdEntry+=(2 + Patch_Count + Tag_Count); /* CRC Packet + PS Reset Packet
+ Patch List + PS List*/ |
| 789 if(Patch_Count > 0) { |
| 790 NumcmdEntry++; /* Patch Enable Command */ |
| 791 } |
| 792 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Num Cmd Entries %d Size %d \r\n",Nu
mcmdEntry,sizeof(PSCmdPacket) * NumcmdEntry)); |
| 793 (*HciPacketList) = A_MALLOC(sizeof(PSCmdPacket) * NumcmdEntry); |
| 794 if(NULL == *HciPacketList) { |
| 795 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("memory allocation failed \r\n"))
; |
| 796 } |
| 797 AthPSCreateHCICommand(PS_VERIFY_CRC,Crc,*HciPacketList,numPackets); |
| 798 if(Patch_Count > 0){ |
| 799 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** Write Patch**** \r\n")); |
| 800 AthPSCreateHCICommand(WRITE_PATCH,Patch_Count,*HciPacketList,num
Packets); |
| 801 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** Enable Patch**** \r\n")); |
| 802 AthPSCreateHCICommand(ENABLE_PATCH,0,*HciPacketList,numPackets); |
| 803 } |
| 804 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** PS Reset**** \r\n")); |
| 805 AthPSCreateHCICommand(PS_RESET,Total_tag_lenght,*HciPacketList,numPacket
s); |
| 806 if(Tag_Count > 0){ |
| 807 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** PS Write**** \r\n")); |
| 808 AthPSCreateHCICommand(PS_WRITE,Tag_Count,*HciPacketList,numPacke
ts); |
| 809 } |
| 810 } |
| 811 if(!BDADDR){ |
| 812 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR not present \r\n")); |
| 813 |
| 814 } |
| 815 for(count = 0; count < Patch_Count; count++) { |
| 816 |
| 817 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing Patch Buffer %d \r\n",count)); |
| 818 A_FREE(RamPatch[Patch_Count].Data); |
| 819 } |
| 820 |
| 821 for(count = 0; count < Tag_Count; count++) { |
| 822 |
| 823 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing PS Buffer %d \r\n",count)); |
| 824 A_FREE(PsTagEntry[count].TagData); |
| 825 } |
| 826 |
| 827 /* |
| 828 * SDIO Transport uses synchronous mode of data transfer |
| 829 * So, AthPSOperations() call returns only after receiving the |
| 830 * command complete event. |
| 831 */ |
| 832 return *numPackets; |
| 833 } |
| 834 |
| 835 |
| 836 //////////////////////// |
| 837 |
| 838 ///////////// |
| 839 static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacke
t *PSPatchPacket,A_UINT32 *index) |
| 840 { |
| 841 A_UCHAR *HCI_PS_Command; |
| 842 A_UINT32 Length; |
| 843 int i,j; |
| 844 |
| 845 switch(Opcode) |
| 846 { |
| 847 case WRITE_PATCH: |
| 848 |
| 849 |
| 850 for(i=0;i< Param1;i++){ |
| 851 |
| 852 HCI_PS_Command = (A_UCHAR *) A_MALLOC(RamPatch[i].Len+HCI_COMMAND_H
EADER); |
| 853 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Allocated Buffer Size %d\n",RamPatc
h[i].Len+HCI_COMMAND_HEADER)); |
| 854 if(HCI_PS_Command == NULL){ |
| 855 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n")); |
| 856 return A_ERROR; |
| 857 } |
| 858 memset (HCI_PS_Command, 0, RamPatch[i].Len+HCI_COMMAND_HEADER); |
| 859 LoadHeader(HCI_PS_Command,Opcode,RamPatch[i].Len,i); |
| 860 for(j=0;j<RamPatch[i].Len;j++){ |
| 861 HCI_PS_Command[HCI_COMMAND_HEADER+j]=RamPatch[i].Data[j]
; |
| 862 } |
| 863 PSPatchPacket[*index].Hcipacket = HCI_PS_Command; |
| 864 PSPatchPacket[*index].packetLen = RamPatch[i].Len+HCI_COMMAND_H
EADER; |
| 865 (*index)++; |
| 866 |
| 867 |
| 868 } |
| 869 |
| 870 break; |
| 871 |
| 872 case ENABLE_PATCH: |
| 873 |
| 874 |
| 875 Length = 0; |
| 876 i= 0; |
| 877 HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND_HEADER); |
| 878 if(HCI_PS_Command == NULL){ |
| 879 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n")); |
| 880 return A_ERROR; |
| 881 } |
| 882 |
| 883 memset (HCI_PS_Command, 0, Length+HCI_COMMAND_HEADER); |
| 884 LoadHeader(HCI_PS_Command,Opcode,Length,i); |
| 885 PSPatchPacket[*index].Hcipacket = HCI_PS_Command; |
| 886 PSPatchPacket[*index].packetLen = Length+HCI_COMMAND_HEADER; |
| 887 (*index)++; |
| 888 |
| 889 break; |
| 890 |
| 891 case PS_RESET: |
| 892 Length = 0x06; |
| 893 i=0; |
| 894 HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND
_HEADER); |
| 895 if(HCI_PS_Command == NULL){ |
| 896 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\
n")); |
| 897 return A_ERROR; |
| 898 } |
| 899 memset (HCI_PS_Command, 0, Length+HCI_COMMAND_HEADER); |
| 900 LoadHeader(HCI_PS_Command,Opcode,Length,i); |
| 901 HCI_PS_Command[7]= 0x00; |
| 902 HCI_PS_Command[Length+HCI_COMMAND_HEADER -2]= (Param1 &
0xFF); |
| 903 HCI_PS_Command[Length+HCI_COMMAND_HEADER -1]= ((Param1 >
> 8) & 0xFF); |
| 904 PSPatchPacket[*index].Hcipacket = HCI_PS_Command; |
| 905 PSPatchPacket[*index].packetLen = Length+HCI_COMMAND_HEADER; |
| 906 (*index)++; |
| 907 |
| 908 break; |
| 909 |
| 910 case PS_WRITE: |
| 911 for(i=0;i< Param1;i++){ |
| 912 if(PsTagEntry[i].TagId ==1) |
| 913 BDADDR = TRUE; |
| 914 |
| 915 HCI_PS_Command = (A_UCHAR *) A_MALLOC(PsTagEntry
[i].TagLen+HCI_COMMAND_HEADER); |
| 916 if(HCI_PS_Command == NULL){ |
| 917 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC F
ailed\r\n")); |
| 918 return A_ERROR; |
| 919 } |
| 920 |
| 921 memset (HCI_PS_Command, 0, PsTagEntry[i].TagLen+
HCI_COMMAND_HEADER); |
| 922 LoadHeader(HCI_PS_Command,Opcode,PsTagEntry[i].T
agLen,PsTagEntry[i].TagId); |
| 923 |
| 924 for(j=0;j<PsTagEntry[i].TagLen;j++){ |
| 925 HCI_PS_Command[HCI_COMMAND_HEADER+j]=PsT
agEntry[i].TagData[j]; |
| 926 } |
| 927 |
| 928 PSPatchPacket[*index].Hcipacket = HCI_PS_Command; |
| 929 PSPatchPacket[*index].packetLen = PsTagEntry[i].TagLen+HCI_
COMMAND_HEADER; |
| 930 (*index)++; |
| 931 |
| 932 } |
| 933 |
| 934 break; |
| 935 |
| 936 |
| 937 case PS_VERIFY_CRC: |
| 938 Length = 0x0; |
| 939 |
| 940 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("VALUE of CRC:%d At index
%d\r\n",Param1,*index)); |
| 941 |
| 942 HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND
_HEADER); |
| 943 if(HCI_PS_Command == NULL){ |
| 944 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\
n")); |
| 945 return A_ERROR; |
| 946 } |
| 947 memset (HCI_PS_Command, 0, Length+HCI_COMMAND_HEADER); |
| 948 LoadHeader(HCI_PS_Command,Opcode,Length,Param1); |
| 949 |
| 950 PSPatchPacket[*index].Hcipacket = HCI_PS_Command; |
| 951 PSPatchPacket[*index].packetLen = Length+HCI_COMMAND_HEADER; |
| 952 (*index)++; |
| 953 |
| 954 break; |
| 955 |
| 956 case CHANGE_BDADDR: |
| 957 break; |
| 958 } |
| 959 return A_OK; |
| 960 } |
| 961 A_STATUS AthFreeCommandList(PSCmdPacket **HciPacketList, A_UINT32 numPackets) |
| 962 { |
| 963 int i; |
| 964 if(*HciPacketList == NULL) { |
| 965 return A_ERROR; |
| 966 } |
| 967 for(i = 0; i < numPackets;i++) { |
| 968 A_FREE((*HciPacketList)[i].Hcipacket); |
| 969 } |
| 970 A_FREE(*HciPacketList); |
| 971 return A_OK; |
| 972 } |
OLD | NEW |