Changeset 283

Show
Ignore:
Timestamp:
08/12/08 12:35:00 (3 months ago)
Author:
pr0gg3d
Message:

fixed some Intersil crash caused by wrong parsing

Location:
trunk/Sources/Driver/USBJack
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/Sources/Driver/USBJack/IntersilJack.mm

    r282 r283  
    248248    KFrame *f = (KFrame *)outBuf; 
    249249 
    250     UInt16 isToDS, isFrDS, subtype, headerLength = 0; 
     250    UInt16 isToDS, isFrDS, subtype, dataLen, headerLength = 0; 
    251251    UInt16 type; 
    252  
     252//    NSLog(@"_massagePacket %d", len); 
    253253    if (len < sizeof(WLFrame)) { 
    254         NSLog(@"WTF, packet len %d shorter than footer %d!", len, sizeof(WLFrame)); 
     254        NSLog(@"WTF, packet len %d shorter than header %d!", len, sizeof(WLFrame)); 
    255255        return false; 
    256256    } 
     
    261261    head->status = NSSwapLittleShortToHost(head->status); 
    262262    if (head->status & 0x1 || (head->status & 0x700) != 0x700 || head->status & 0xe000) { 
    263         return false; 
    264     } 
    265       
    266  
     263        NSLog(@"FCS error"); 
     264        return false; 
     265    } 
     266    dataLen = NSSwapLittleShortToHost(head->dataLen); 
     267//    NSLog(@"dataLen %d", dataLen); 
    267268    type = (head->frameControl & IEEE80211_TYPE_MASK); 
    268     //depending on the frame we have to figure the length of the header 
     269    subtype = (head->frameControl & IEEE80211_SUBTYPE_MASK); 
     270    isToDS = ((head->frameControl & IEEE80211_DIR_TODS) ? YES : NO); 
     271    isFrDS = ((head->frameControl & IEEE80211_DIR_FROMDS) ? YES : NO); 
    269272    switch(type) { 
    270         case IEEE80211_TYPE_DATA: //Data Frames 
    271             isToDS = ((head->frameControl & IEEE80211_DIR_TODS) ? YES : NO); 
    272             isFrDS = ((head->frameControl & IEEE80211_DIR_FROMDS) ? YES : NO); 
    273             if (isToDS&&isFrDS) 
    274                 headerLength=30; //WDS Frames are longer 
    275             else 
    276                 headerLength=24; 
     273        case IEEE80211_TYPE_MGT: 
     274//            NSLog(@"MANAGEMENT"); 
     275            headerLength = sizeof(struct ieee80211_hdr_3addr); 
    277276            break; 
    278             case IEEE80211_TYPE_CTL: //Control Frames 
    279                 subtype=(head->frameControl & IEEE80211_SUBTYPE_MASK); 
    280                 switch(subtype) { 
    281                     case IEEE80211_SUBTYPE_PS_POLL: 
    282                     case IEEE80211_SUBTYPE_RTS: 
    283                         headerLength=16; 
    284                         break; 
    285                     case IEEE80211_SUBTYPE_CTS: 
    286                     case IEEE80211_SUBTYPE_ACK: 
    287                         headerLength=10; 
    288                         break; 
    289                     default: 
    290                         break; 
     277        case IEEE80211_TYPE_DATA: 
     278//            NSLog(@"DATA"); 
     279            if (subtype == IEEE80211_SUBTYPE_QOS_DATA) { 
     280//                NSLog(@"QOS"); 
     281                if (isFrDS && isToDS) { 
     282//                    NSLog(@"isFrDS && isToDS"); 
     283                    headerLength = sizeof(struct ieee80211_hdr_4addrqos); 
     284                } else { 
     285//                    NSLog(@"isFrDS || isToDS"); 
     286                    headerLength = sizeof(struct ieee80211_hdr_3addrqos);                     
    291287                } 
    292                 break; 
    293             case IEEE80211_TYPE_MGT: //Management Frame 
    294                 headerLength=24; 
     288            } else { 
     289//                NSLog(@"NO QOS"); 
     290                if (isFrDS && isToDS) { 
     291//                    NSLog(@"isFrDS && isToDS"); 
     292                    headerLength = sizeof(struct ieee80211_hdr_4addr); 
     293                } else { 
     294//                    NSLog(@"isFrDS || isToDS"); 
     295                    headerLength = sizeof(struct ieee80211_hdr_3addr);                     
     296                } 
     297            } 
    295298            break; 
     299        case IEEE80211_TYPE_CTL: 
     300//            NSLog(@"CTL"); 
     301            switch(subtype) { 
     302                case IEEE80211_SUBTYPE_PS_POLL: 
     303                case IEEE80211_SUBTYPE_RTS: 
     304                    headerLength=16; 
     305                    break; 
     306                case IEEE80211_SUBTYPE_CTS: 
     307                case IEEE80211_SUBTYPE_ACK: 
     308                    headerLength=10; 
     309                    break; 
    296310                default: 
     311                    return false; 
     312                    break; 
     313            } 
    297314            break; 
    298     } 
    299      
    300     NSLog(@"dataLen %d", CFSwapInt16LittleToHost(head->dataLen)); 
     315        default: 
     316            NSLog(@"Unknown frame type %u", type); 
     317            return false; 
     318    } 
     319 
    301320    memcpy(f->data, pData+sizeof(WLPrismHeader), headerLength); 
    302     memcpy((f->data)+24, pData+sizeof(WLFrame), len-sizeof(WLFrame)); 
    303     f->ctrl.len = CFSwapInt16LittleToHost(head->dataLen) + headerLength; 
     321    if (headerLength >= sizeof(struct ieee80211_hdr_3addr)) 
     322        memcpy(f->data + 24, pData+sizeof(WLFrame), dataLen); 
     323    else 
     324        dataLen = 0; 
     325    f->ctrl.len = dataLen+headerLength; 
    304326    f->ctrl.signal = head->silence; 
    305327    f->ctrl.channel = head->channel; 
  • trunk/Sources/Driver/USBJack/USBJack.mm

    r282 r283  
    379379         
    380380        frame = (KFrame*)&(me->_receiveBuffer.rxfrm); 
    381  
     381//        NSLog(@"dataReceived %d", len); 
    382382        // Why do we needs to convert ? 
    383383//        frameDescriptor->status = NSSwapLittleShortToHost(frameDescriptor->status); 
     
    442442     
    443443readon: 
    444 //    bzero(&me->_receiveBuffer, sizeof(me->_receiveBuffer)); 
     444    bzero(&me->_receiveBuffer, sizeof(me->_receiveBuffer)); 
    445445    kr = (*me->_interface)->ReadPipeAsync((me->_interface), (me->kInPipe), &me->_receiveBuffer, sizeof(me->_receiveBuffer), (IOAsyncCallback1)_interruptReceived, refCon); 
    446446    if (kIOReturnSuccess != kr) {