Ticket #7822: horst_big_endian_fix.patch

File horst_big_endian_fix.patch, 3.2 KB (added by jal2@…, 6 years ago)

handle little endian values on big endian machines correctly

  • protocol_parser.c

    diff -r -Nurp horst-2.0-rc1.orig/protocol_parser.c horst-2.0-rc1/protocol_parser.c
    old new  
    2323#include <net/if_arp.h> 
    2424#include <netinet/ip.h> 
    2525#include <netinet/udp.h> 
     26#include <asm/byteorder.h> 
    2627 
    2728#include "prism_header.h" 
    2829#include "ieee80211_radiotap.h" 
    parse_radiotap_header(unsigned char** bu 
    166167        __le32 present; /* the present bitmap */ 
    167168        unsigned char* b; /* current byte */ 
    168169        int i; 
     170        int rt_len; 
    169171 
    170172        DEBUG("RADIOTAP HEADER\n"); 
    171173 
    parse_radiotap_header(unsigned char** bu 
    176178 
    177179        rh = (struct ieee80211_radiotap_header*)*buf; 
    178180        b = *buf + sizeof(struct ieee80211_radiotap_header); 
    179         present = rh->it_present; 
     181        present = __le32_to_cpu(rh->it_present); 
    180182 
    181183        DEBUG("%08x\n", present); 
    182184 
     185        rt_len = __le16_to_cpu(rh->it_len); 
    183186        /* check for header extension - ignore for now, just advance current position */ 
    184         while (present & 0x80000000  && b - *buf < rh->it_len) { 
     187        while (present & 0x80000000  && b - *buf < rt_len) { 
    185188                DEBUG("extension\n"); 
    186189                b = b + 4; 
    187                 present = *(__le32*)b; 
     190                present = __le32_to_cpu(*(__le32*)b); 
    188191        } 
    189         present = rh->it_present; // in case it moved 
     192        present = __le32_to_cpu(rh->it_present); // in case it moved 
    190193 
    191194        /* radiotap bitmap has 32 bit, but we are only interrested until 
    192195         * bit 12 (IEEE80211_RADIOTAP_DB_ANTSIGNAL) => i<13 */ 
    193         for (i = 0; i < 13 && b - *buf < rh->it_len; i++) { 
     196        for (i = 0; i < 13 && b - *buf < rt_len; i++) { 
    194197                if ((present >> i) & 1) { 
    195198                        DEBUG("1"); 
    196199                        switch (i) { 
    parse_radiotap_header(unsigned char** bu 
    252255                                        break; 
    253256                                case IEEE80211_RADIOTAP_CHANNEL: 
    254257                                        /* channel & channel type */ 
    255                                         current_packet.phy_freq = *(u_int16_t*)b; 
     258                                        current_packet.phy_freq = __le16_to_cpu(*(u_int16_t*)b); 
    256259                                        DEBUG("[chan %d ", current_packet.phy_freq); 
    257260                                        b = b + 2; 
    258261                                        if (*(u_int16_t*)b & IEEE80211_CHAN_A) { 
    parse_radiotap_header(unsigned char** bu 
    298301        DEBUG("noise: %d\n", current_packet.noise); 
    299302        DEBUG("snr: %d\n", current_packet.snr); 
    300303 
    301         *buf = *buf + rh->it_len; 
    302         return len - rh->it_len; 
     304        *buf = *buf + rt_len; 
     305        return len - rt_len; 
    303306} 
    304307 
    305308 
    parse_80211_header(unsigned char** buf,  
    312315        u8* sa = NULL; 
    313316        u8* da = NULL; 
    314317        u8* bssid = NULL; 
     318        u16 fc; 
    315319 
    316320        if (len < 2) /* not even enough space for fc */ 
    317321                return -1; 
    318322 
    319323        wh = (struct ieee80211_hdr*)*buf; 
    320         hdrlen = ieee80211_get_hdrlen(wh->frame_control); 
     324        fc = __le16_to_cpu(wh->frame_control); 
     325        hdrlen = ieee80211_get_hdrlen(fc); 
    321326 
    322327        if (len < hdrlen) 
    323328                return -1; 
    324329 
    325330        current_packet.len = len; 
    326         current_packet.wlan_type = (wh->frame_control & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)); 
     331        current_packet.wlan_type = (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)); 
    327332 
    328         DEBUG("wlan_type %x - type %x - stype %x\n", wh->frame_control, wh->frame_control & IEEE80211_FCTL_FTYPE, wh->frame_control & IEEE80211_FCTL_STYPE ); 
     333        DEBUG("wlan_type %x - type %x - stype %x\n", fc,  
     334              fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE ); 
    329335 
    330         DEBUG("%s\n", get_packet_type_name(wh->frame_control)); 
     336        DEBUG("%s\n", get_packet_type_name(fc)); 
    331337 
    332338        bssid = ieee80211_get_bssid(wh, len); 
    333339