0c37c169f5fb93f3cdd5a2b450f57e33e8ba34db
[packages.git] / net / horst / patches / 001-endian_fixes.patch
1 --- a/protocol_parser.c
2 +++ b/protocol_parser.c
3 @@ -23,6 +23,7 @@
4  #include <net/if_arp.h>
5  #include <netinet/ip.h>
6  #include <netinet/udp.h>
7 +#include <asm/byteorder.h>
8  
9  #include "prism_header.h"
10  #include "ieee80211_radiotap.h"
11 @@ -166,6 +167,7 @@ parse_radiotap_header(unsigned char** bu
12         __le32 present; /* the present bitmap */
13         unsigned char* b; /* current byte */
14         int i;
15 +       int rt_len;
16  
17         DEBUG("RADIOTAP HEADER\n");
18  
19 @@ -176,21 +178,22 @@ parse_radiotap_header(unsigned char** bu
20  
21         rh = (struct ieee80211_radiotap_header*)*buf;
22         b = *buf + sizeof(struct ieee80211_radiotap_header);
23 -       present = rh->it_present;
24 +       present = __le32_to_cpu(rh->it_present);
25  
26         DEBUG("%08x\n", present);
27  
28 +       rt_len = __le16_to_cpu(rh->it_len);
29         /* check for header extension - ignore for now, just advance current position */
30 -       while (present & 0x80000000  && b - *buf < rh->it_len) {
31 +       while (present & 0x80000000  && b - *buf < rt_len) {
32                 DEBUG("extension\n");
33                 b = b + 4;
34 -               present = *(__le32*)b;
35 +               present = __le32_to_cpu(*(__le32*)b);
36         }
37 -       present = rh->it_present; // in case it moved
38 +       present = __le32_to_cpu(rh->it_present); // in case it moved
39  
40         /* radiotap bitmap has 32 bit, but we are only interrested until
41          * bit 12 (IEEE80211_RADIOTAP_DB_ANTSIGNAL) => i<13 */
42 -       for (i = 0; i < 13 && b - *buf < rh->it_len; i++) {
43 +       for (i = 0; i < 13 && b - *buf < rt_len; i++) {
44                 if ((present >> i) & 1) {
45                         DEBUG("1");
46                         switch (i) {
47 @@ -252,7 +255,7 @@ parse_radiotap_header(unsigned char** bu
48                                         break;
49                                 case IEEE80211_RADIOTAP_CHANNEL:
50                                         /* channel & channel type */
51 -                                       current_packet.phy_freq = *(u_int16_t*)b;
52 +                                       current_packet.phy_freq = __le16_to_cpu(*(u_int16_t*)b);
53                                         DEBUG("[chan %d ", current_packet.phy_freq);
54                                         b = b + 2;
55                                         if (*(u_int16_t*)b & IEEE80211_CHAN_A) {
56 @@ -298,8 +301,8 @@ parse_radiotap_header(unsigned char** bu
57         DEBUG("noise: %d\n", current_packet.noise);
58         DEBUG("snr: %d\n", current_packet.snr);
59  
60 -       *buf = *buf + rh->it_len;
61 -       return len - rh->it_len;
62 +       *buf = *buf + rt_len;
63 +       return len - rt_len;
64  }
65  
66  
67 @@ -312,22 +315,25 @@ parse_80211_header(unsigned char** buf, 
68         u8* sa = NULL;
69         u8* da = NULL;
70         u8* bssid = NULL;
71 +       u16 fc;
72  
73         if (len < 2) /* not even enough space for fc */
74                 return -1;
75  
76         wh = (struct ieee80211_hdr*)*buf;
77 -       hdrlen = ieee80211_get_hdrlen(wh->frame_control);
78 +       fc = __le16_to_cpu(wh->frame_control);
79 +       hdrlen = ieee80211_get_hdrlen(fc);
80  
81         if (len < hdrlen)
82                 return -1;
83  
84         current_packet.len = len;
85 -       current_packet.wlan_type = (wh->frame_control & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE));
86 +       current_packet.wlan_type = (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE));
87  
88 -       DEBUG("wlan_type %x - type %x - stype %x\n", wh->frame_control, wh->frame_control & IEEE80211_FCTL_FTYPE, wh->frame_control & IEEE80211_FCTL_STYPE );
89 +       DEBUG("wlan_type %x - type %x - stype %x\n", fc, 
90 +             fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE );
91  
92 -       DEBUG("%s\n", get_packet_type_name(wh->frame_control));
93 +       DEBUG("%s\n", get_packet_type_name(fc));
94  
95         bssid = ieee80211_get_bssid(wh, len);
96