~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
 
88
88
typedef struct tPsTagEntry
89
89
{
90
 
   A_UINT32   TagId;
91
 
   A_UINT32   TagLen;
92
 
   A_UINT8    *TagData;
 
90
   u32 TagId;
 
91
   u32 TagLen;
 
92
   u8 *TagData;
93
93
} tPsTagEntry, *tpPsTagEntry;
94
94
 
95
95
typedef struct tRamPatch
96
96
{
97
 
   A_UINT16   Len;
98
 
   A_UINT8    * Data;
 
97
   u16 Len;
 
98
   u8 *Data;
99
99
} tRamPatch, *ptRamPatch;
100
100
 
101
101
 
102
102
 
103
 
typedef struct ST_PS_DATA_FORMAT {
 
103
struct st_ps_data_format {
104
104
   enum eType   eDataType;
105
 
   A_BOOL    bIsArray;
106
 
}ST_PS_DATA_FORMAT;
 
105
   bool    bIsArray;
 
106
};
107
107
 
108
 
typedef struct ST_READ_STATUS {
 
108
struct st_read_status {
109
109
    unsigned uTagID;
110
110
    unsigned uSection;
111
111
    unsigned uLineCount;
112
112
    unsigned uCharCount;
113
113
    unsigned uByteCount;
114
 
}ST_READ_STATUS;
 
114
};
115
115
 
116
116
 
117
117
/* Stores the number of PS Tags */
118
 
static A_UINT32 Tag_Count = 0;
 
118
static u32 Tag_Count = 0;
119
119
 
120
120
/* Stores the number of patch commands */
121
 
static A_UINT32 Patch_Count = 0;
122
 
static A_UINT32 Total_tag_lenght = 0;
123
 
A_BOOL BDADDR = FALSE;
124
 
A_UINT32      StartTagId;
 
121
static u32 Patch_Count = 0;
 
122
static u32 Total_tag_lenght = 0;
 
123
bool BDADDR = false;
 
124
u32 StartTagId;
125
125
 
126
126
tPsTagEntry PsTagEntry[RAMPS_MAX_PS_TAGS_PER_FILE];
127
127
tRamPatch   RamPatch[MAX_NUM_PATCH_ENTRY];
128
128
 
129
129
 
130
 
A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat);
131
 
char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos);
132
 
char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_UINT32 *pos);
133
 
static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacket *PSPatchPacket,A_UINT32 *index);
 
130
int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat);
 
131
char AthReadChar(u8 *buffer, u32 len,u32 *pos);
 
132
char *AthGetLine(char *buffer, int maxlen, u8 *srcbuffer,u32 len,u32 *pos);
 
133
static int AthPSCreateHCICommand(u8 Opcode, u32 Param1,struct ps_cmd_packet *PSPatchPacket,u32 *index);
134
134
 
135
135
/* Function to reads the next character from the input buffer */
136
 
char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos) 
 
136
char AthReadChar(u8 *buffer, u32 len,u32 *pos)
137
137
{
138
138
    char Ch;
139
139
    if(buffer == NULL || *pos >=len )
146
146
    }
147
147
}
148
148
/* PS parser helper function */
149
 
unsigned int uGetInputDataFormat(char* pCharLine, ST_PS_DATA_FORMAT *pstFormat) 
 
149
unsigned int uGetInputDataFormat(char *pCharLine, struct st_ps_data_format *pstFormat)
150
150
{
151
151
    if(pCharLine[0] != '[') {
152
152
        pstFormat->eDataType = eHex;
286
286
    }
287
287
}
288
288
 
289
 
unsigned int uReadDataInSection(char *pCharLine, ST_PS_DATA_FORMAT stPS_DataFormat)
 
289
unsigned int uReadDataInSection(char *pCharLine, struct st_ps_data_format stPS_DataFormat)
290
290
{
291
291
    char *pTokenPtr = pCharLine;
292
292
 
315
315
        return (0x0FFF);
316
316
    }
317
317
}
318
 
A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat)
 
318
int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat)
319
319
{
320
 
   char     *Buffer;
321
 
   char     *pCharLine;
322
 
   A_UINT8    TagCount;
323
 
   A_UINT16   ByteCount;
324
 
   A_UINT8    ParseSection=RAM_PS_SECTION;
325
 
   A_UINT32 pos;
 
320
   char *Buffer;
 
321
   char *pCharLine;
 
322
   u8 TagCount;
 
323
   u16 ByteCount;
 
324
   u8 ParseSection=RAM_PS_SECTION;
 
325
   u32 pos;
326
326
 
327
327
 
328
328
 
329
329
   int uReadCount;
330
 
   ST_PS_DATA_FORMAT stPS_DataFormat;
331
 
   ST_READ_STATUS   stReadStatus = {0, 0, 0,0};
 
330
   struct st_ps_data_format stPS_DataFormat;
 
331
   struct st_read_status   stReadStatus = {0, 0, 0,0};
332
332
   pos = 0;
333
333
   Buffer = NULL;
334
334
 
362
362
             {
363
363
                 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("error\n"));
364
364
                 if(Buffer != NULL) {
365
 
                     A_FREE(Buffer);
 
365
                     kfree(Buffer);
366
366
                 }
367
367
                 return A_ERROR;
368
368
             }
401
401
                    if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) {
402
402
                        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail\n"));
403
403
                     if(Buffer != NULL) {
404
 
                             A_FREE(Buffer);
 
404
                             kfree(Buffer);
405
405
                     }
406
406
                        return A_ERROR;
407
407
                    }    
422
422
                    if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) {
423
423
                        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail \n"));
424
424
                     if(Buffer != NULL) {
425
 
                             A_FREE(Buffer);
 
425
                             kfree(Buffer);
426
426
                     }
427
427
                        return A_ERROR;
428
428
                    }
433
433
                    if (ByteCount > LINE_SIZE_MAX/2)
434
434
                    {
435
435
                     if(Buffer != NULL) {
436
 
                             A_FREE(Buffer);
 
436
                             kfree(Buffer);
437
437
                     }
438
438
                       return A_ERROR;
439
439
                    }
440
440
                    PsTagEntry[TagCount].TagLen = ByteCount;
441
 
                    PsTagEntry[TagCount].TagData = (A_UINT8*)A_MALLOC(ByteCount);
 
441
                    PsTagEntry[TagCount].TagData = (u8 *)A_MALLOC(ByteCount);
442
442
                    AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" TAG Length %d  Tag Index %d \n",PsTagEntry[TagCount].TagLen,TagCount));
443
443
                    stReadStatus.uSection = 3;
444
444
                    stReadStatus.uLineCount = 0;
449
449
                        if(uGetInputDataFormat(pCharLine,&stPS_DataFormat)) {
450
450
                            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat Fail\n"));
451
451
                            if(Buffer != NULL) {
452
 
                                 A_FREE(Buffer);
 
452
                                 kfree(Buffer);
453
453
                         }
454
454
                            return A_ERROR;
455
455
                        }
472
472
                    if((stPS_DataFormat.eDataType == eHex) && stPS_DataFormat.bIsArray == true) {
473
473
                       while(uReadCount > 0) {
474
474
                           PsTagEntry[TagCount].TagData[stReadStatus.uByteCount] =
475
 
                                                     (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount]) << 4)
476
 
                                                     | (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 1]));
 
475
                                                     (u8)(hex_to_bin(pCharLine[stReadStatus.uCharCount]) << 4)
 
476
                                                     | (u8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 1]));
477
477
 
478
478
                           PsTagEntry[TagCount].TagData[stReadStatus.uByteCount+1] =
479
 
                                                     (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 3]) << 4)
480
 
                                                     | (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 4]));
 
479
                                                     (u8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 3]) << 4)
 
480
                                                     | (u8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 4]));
481
481
 
482
482
                           stReadStatus.uCharCount += 6; // read two bytes, plus a space;
483
483
                           stReadStatus.uByteCount += 2;
510
510
                    {
511
511
                       AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("\n Buffer over flow PS File too big!!!"));
512
512
                       if(Buffer != NULL) {
513
 
                           A_FREE(Buffer);
 
513
                           kfree(Buffer);
514
514
                       }
515
515
                       return A_ERROR;
516
516
                       //Sleep (3000);
524
524
             default:
525
525
             {
526
526
                   if(Buffer != NULL) {
527
 
                       A_FREE(Buffer);
 
527
                       kfree(Buffer);
528
528
                   }
529
529
                   return A_ERROR;
530
530
             }
541
541
   {
542
542
 
543
543
      if(Buffer != NULL) {
544
 
           A_FREE(Buffer);
 
544
           kfree(Buffer);
545
545
      }
546
546
      return A_ERROR;
547
547
   }
548
548
 
549
549
   if(Buffer != NULL) {
550
 
        A_FREE(Buffer);
 
550
        kfree(Buffer);
551
551
   }
552
 
   return A_OK;
 
552
   return 0;
553
553
 
554
554
}
555
555
 
558
558
/********************/
559
559
 
560
560
 
561
 
A_STATUS GetNextTwoChar(A_UCHAR *srcbuffer,A_UINT32 len, A_UINT32 *pos, char * buffer)
 
561
int GetNextTwoChar(u8 *srcbuffer,u32 len, u32 *pos, char *buffer)
562
562
{
563
563
    unsigned char ch;
564
564
 
576
576
    {
577
577
        return A_ERROR;
578
578
    }
579
 
    return A_OK;
 
579
    return 0;
580
580
}
581
581
 
582
 
A_STATUS AthDoParsePatch(A_UCHAR *patchbuffer, A_UINT32 patchlen)
 
582
int AthDoParsePatch(u8 *patchbuffer, u32 patchlen)
583
583
{
584
584
 
585
 
    char  Byte[3];
586
 
    char   Line[MAX_BYTE_LENGTH + 1];
 
585
    char Byte[3];
 
586
    char Line[MAX_BYTE_LENGTH + 1];
587
587
    int    ByteCount,ByteCount_Org;
588
588
    int count;
589
589
    int i,j,k;
590
590
    int data;
591
 
    A_UINT32 filepos;
 
591
    u32 filepos;
592
592
    Byte[2] = '\0';
593
593
    j = 0;
594
594
    filepos = 0;
609
609
        /* Handle case when the number of patch buffer is more than the 20K */
610
610
        if(MAX_NUM_PATCH_ENTRY == Patch_Count) {
611
611
            for(i = 0; i < Patch_Count; i++) {
612
 
                A_FREE(RamPatch[i].Data);
 
612
                kfree(RamPatch[i].Data);
613
613
            }
614
614
            return A_ERROR;
615
615
        }
616
616
        RamPatch[Patch_Count].Len= MAX_BYTE_LENGTH;
617
 
        RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(MAX_BYTE_LENGTH);
 
617
        RamPatch[Patch_Count].Data = (u8 *)A_MALLOC(MAX_BYTE_LENGTH);
618
618
        Patch_Count ++;
619
619
 
620
620
 
623
623
 
624
624
    RamPatch[Patch_Count].Len= (ByteCount & 0xFF);
625
625
    if(ByteCount != 0) {
626
 
        RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(ByteCount);
 
626
        RamPatch[Patch_Count].Data = (u8 *)A_MALLOC(ByteCount);
627
627
        Patch_Count ++;
628
628
    }
629
629
    count = 0;
654
654
 
655
655
 
656
656
    }
657
 
    return A_OK;
 
657
    return 0;
658
658
}
659
659
 
660
660
 
661
661
/********************/
662
 
A_STATUS AthDoParsePS(A_UCHAR *srcbuffer, A_UINT32 srclen)
 
662
int AthDoParsePS(u8 *srcbuffer, u32 srclen)
663
663
{
664
 
    A_STATUS status;
 
664
    int status;
665
665
    int i;
666
 
    A_BOOL BDADDR_Present = A_ERROR;
 
666
    bool BDADDR_Present = false;
667
667
 
668
668
    Tag_Count = 0;
669
669
 
670
670
    Total_tag_lenght = 0;
671
 
    BDADDR = FALSE;
 
671
    BDADDR = false;
672
672
 
673
673
 
674
674
    status = A_ERROR;
689
689
        else{
690
690
                for(i=0; i<Tag_Count; i++){
691
691
                        if(PsTagEntry[i].TagId == 1){
692
 
                                BDADDR_Present = A_OK;
 
692
                                BDADDR_Present = true;
693
693
                                AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR is present in Patch File \r\n"));
694
694
 
695
695
                        }
713
713
 
714
714
    return status;
715
715
}
716
 
char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_UINT32 *pos)
 
716
char *AthGetLine(char *buffer, int maxlen, u8 *srcbuffer,u32 len,u32 *pos)
717
717
{
718
718
 
719
719
    int count;
751
751
    return buffer;
752
752
}
753
753
 
754
 
static void LoadHeader(A_UCHAR *HCI_PS_Command,A_UCHAR opcode,int length,int index){
 
754
static void LoadHeader(u8 *HCI_PS_Command,u8 opcode,int length,int index){
755
755
 
756
756
        HCI_PS_Command[0]= 0x0B;
757
757
        HCI_PS_Command[1]= 0xFC;
764
764
 
765
765
/////////////////////////
766
766
//
767
 
int AthCreateCommandList(PSCmdPacket **HciPacketList, A_UINT32 *numPackets)
 
767
int AthCreateCommandList(struct ps_cmd_packet **HciPacketList, u32 *numPackets)
768
768
{
769
769
 
770
 
    A_UINT8 count;
771
 
    A_UINT32 NumcmdEntry = 0; 
 
770
    u8 count;
 
771
    u32 NumcmdEntry = 0;
772
772
 
773
 
    A_UINT32 Crc = 0;
 
773
    u32 Crc = 0;
774
774
    *numPackets = 0;
775
775
 
776
776
 
785
785
        if(Patch_Count > 0) {
786
786
            NumcmdEntry++; /* Patch Enable Command */
787
787
        }
788
 
           AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Num Cmd Entries %d Size  %d  \r\n",NumcmdEntry,(A_UINT32)sizeof(PSCmdPacket) * NumcmdEntry));
789
 
        (*HciPacketList) = A_MALLOC(sizeof(PSCmdPacket) * NumcmdEntry);
 
788
           AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Num Cmd Entries %d Size  %d  \r\n",NumcmdEntry,(u32)sizeof(struct ps_cmd_packet) * NumcmdEntry));
 
789
        (*HciPacketList) = A_MALLOC(sizeof(struct ps_cmd_packet) * NumcmdEntry);
790
790
    if(NULL == *HciPacketList) {
791
791
               AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("memory allocation failed  \r\n"));
792
792
        }
812
812
    for(count = 0; count < Patch_Count; count++) {
813
813
 
814
814
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing Patch Buffer %d \r\n",count));
815
 
        A_FREE(RamPatch[Patch_Count].Data);
 
815
        kfree(RamPatch[Patch_Count].Data);
816
816
    }
817
817
 
818
818
    for(count = 0; count < Tag_Count; count++) {
819
819
 
820
820
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing PS Buffer %d \r\n",count));
821
 
        A_FREE(PsTagEntry[count].TagData);
 
821
        kfree(PsTagEntry[count].TagData);
822
822
    }
823
823
 
824
824
/* 
833
833
////////////////////////
834
834
 
835
835
/////////////
836
 
static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacket *PSPatchPacket,A_UINT32 *index)
 
836
static int AthPSCreateHCICommand(u8 Opcode, u32 Param1,struct ps_cmd_packet *PSPatchPacket,u32 *index)
837
837
{
838
 
    A_UCHAR *HCI_PS_Command;
839
 
    A_UINT32 Length;
 
838
    u8 *HCI_PS_Command;
 
839
    u32 Length;
840
840
    int i,j;
841
841
    
842
842
    switch(Opcode)
846
846
 
847
847
         for(i=0;i< Param1;i++){
848
848
 
849
 
             HCI_PS_Command = (A_UCHAR *) A_MALLOC(RamPatch[i].Len+HCI_COMMAND_HEADER);
 
849
             HCI_PS_Command = (u8 *) A_MALLOC(RamPatch[i].Len+HCI_COMMAND_HEADER);
850
850
             AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Allocated Buffer Size %d\n",RamPatch[i].Len+HCI_COMMAND_HEADER));
851
851
                 if(HCI_PS_Command == NULL){
852
852
                     AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n"));
871
871
 
872
872
         Length = 0;
873
873
         i= 0;
874
 
         HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND_HEADER);
 
874
         HCI_PS_Command = (u8 *) A_MALLOC(Length+HCI_COMMAND_HEADER);
875
875
         if(HCI_PS_Command == NULL){
876
876
             AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n"));
877
877
            return A_ERROR;
888
888
    case PS_RESET:
889
889
                        Length = 0x06;
890
890
                        i=0;
891
 
                        HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND_HEADER);
 
891
                        HCI_PS_Command = (u8 *) A_MALLOC(Length+HCI_COMMAND_HEADER);
892
892
                        if(HCI_PS_Command == NULL){
893
893
                                AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n"));
894
894
                                return A_ERROR;
907
907
    case PS_WRITE:
908
908
                       for(i=0;i< Param1;i++){
909
909
                                if(PsTagEntry[i].TagId ==1)
910
 
                                        BDADDR = TRUE;
 
910
                                        BDADDR = true;
911
911
 
912
 
                                HCI_PS_Command = (A_UCHAR *) A_MALLOC(PsTagEntry[i].TagLen+HCI_COMMAND_HEADER);
 
912
                                HCI_PS_Command = (u8 *) A_MALLOC(PsTagEntry[i].TagLen+HCI_COMMAND_HEADER);
913
913
                                if(HCI_PS_Command == NULL){
914
914
                                        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n"));
915
915
                                        return A_ERROR;
936
936
 
937
937
                        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("VALUE of CRC:%d At index %d\r\n",Param1,*index));
938
938
 
939
 
                        HCI_PS_Command = (A_UCHAR *) A_MALLOC(Length+HCI_COMMAND_HEADER);
 
939
                        HCI_PS_Command = (u8 *) A_MALLOC(Length+HCI_COMMAND_HEADER);
940
940
                        if(HCI_PS_Command == NULL){
941
941
                                AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n"));
942
942
                                return A_ERROR;
953
953
    case CHANGE_BDADDR:
954
954
    break;
955
955
    }
956
 
    return A_OK;
 
956
    return 0;
957
957
}
958
 
A_STATUS AthFreeCommandList(PSCmdPacket **HciPacketList, A_UINT32 numPackets)
 
958
int AthFreeCommandList(struct ps_cmd_packet **HciPacketList, u32 numPackets)
959
959
{
960
960
    int i;
961
961
    if(*HciPacketList == NULL) {
962
962
        return A_ERROR;
963
963
    }
964
964
    for(i = 0; i < numPackets;i++) {
965
 
        A_FREE((*HciPacketList)[i].Hcipacket);
 
965
        kfree((*HciPacketList)[i].Hcipacket);
966
966
    }  
967
 
    A_FREE(*HciPacketList);
968
 
    return A_OK;
 
967
    kfree(*HciPacketList);
 
968
    return 0;
969
969
}