diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-14 15:02:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-14 15:02:53 +0000 |
commit | 09923f6cb3e8ff97586824c57f34d7d38e0c0986 (patch) | |
tree | 66ade3702ca8500100acfa05b139cd463d456fee /src/transport/gnunet-transport-wlan-sender.c | |
parent | f326fb85c52d9b7c13023c98795674c379269349 (diff) | |
download | gnunet-09923f6cb3e8ff97586824c57f34d7d38e0c0986.tar.gz gnunet-09923f6cb3e8ff97586824c57f34d7d38e0c0986.zip |
-fixing some of the issues from #1939 -- untested
Diffstat (limited to 'src/transport/gnunet-transport-wlan-sender.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-sender.c | 76 |
1 files changed, 26 insertions, 50 deletions
diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c index 651b4d413..a6280bc7d 100644 --- a/src/transport/gnunet-transport-wlan-sender.c +++ b/src/transport/gnunet-transport-wlan-sender.c | |||
@@ -46,35 +46,22 @@ | |||
46 | #define IEEE80211_FC0_TYPE_CTL 0x04 | 46 | #define IEEE80211_FC0_TYPE_CTL 0x04 |
47 | #define IEEE80211_FC0_TYPE_DATA 0x08 | 47 | #define IEEE80211_FC0_TYPE_DATA 0x08 |
48 | 48 | ||
49 | GNUNET_NETWORK_STRUCT_BEGIN | ||
50 | |||
51 | /* | ||
52 | * generic definitions for IEEE 802.11 frames | ||
53 | */ | ||
54 | struct ieee80211_frame | ||
55 | { | ||
56 | u_int8_t i_fc[2]; | ||
57 | u_int8_t i_dur[2]; | ||
58 | u_int8_t i_addr1[IEEE80211_ADDR_LEN]; | ||
59 | u_int8_t i_addr2[IEEE80211_ADDR_LEN]; | ||
60 | u_int8_t i_addr3[IEEE80211_ADDR_LEN]; | ||
61 | u_int8_t i_seq[2]; | ||
62 | u_int8_t llc[4]; | ||
63 | } GNUNET_PACKED; | ||
64 | GNUNET_NETWORK_STRUCT_END | ||
65 | 49 | ||
66 | /** | 50 | /** |
67 | * function to fill the radiotap header | 51 | * function to fill the radiotap header |
68 | * @param header pointer to the radiotap header | 52 | * @param header pointer to the radiotap header |
53 | * @param size total message size | ||
69 | * @return GNUNET_YES at success | 54 | * @return GNUNET_YES at success |
70 | */ | 55 | */ |
71 | static int | 56 | static int |
72 | getRadiotapHeader (struct Radiotap_Send *header) | 57 | getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, |
58 | uint16_t size) | ||
73 | { | 59 | { |
60 | header->header.size = htons (size); | ||
61 | header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | ||
74 | header->rate = 255; | 62 | header->rate = 255; |
75 | header->tx_power = 0; | 63 | header->tx_power = 0; |
76 | header->antenna = 0; | 64 | header->antenna = 0; |
77 | |||
78 | return GNUNET_YES; | 65 | return GNUNET_YES; |
79 | } | 66 | } |
80 | 67 | ||
@@ -87,23 +74,21 @@ getRadiotapHeader (struct Radiotap_Send *header) | |||
87 | * @return GNUNET_YES if there was no error | 74 | * @return GNUNET_YES if there was no error |
88 | */ | 75 | */ |
89 | static int | 76 | static int |
90 | getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr, | 77 | getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, |
91 | const char *mac, unsigned int size) | 78 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, |
79 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size) | ||
92 | { | 80 | { |
93 | uint16_t *tmp16; | ||
94 | const int rate = 11000000; | 81 | const int rate = 11000000; |
95 | 82 | ||
96 | Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; | 83 | Header->frame_control = htons (IEEE80211_FC0_TYPE_DATA); |
97 | Header->i_fc[1] = 0x00; | 84 | Header->addr3 = mac_bssid_gnunet; |
98 | memcpy (&Header->i_addr3, &mac_bssid_gnunet, sizeof (mac_bssid_gnunet)); | 85 | Header->addr2 = *mac; |
99 | memcpy (&Header->i_addr2, mac, sizeof (mac_bssid_gnunet)); | 86 | Header->addr1 = *to_mac_addr; |
100 | memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid_gnunet)); | 87 | Header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290); |
101 | |||
102 | tmp16 = (uint16_t *) Header->i_dur; | ||
103 | *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290); | ||
104 | Header->llc[0] = WLAN_LLC_DSAP_FIELD; | 88 | Header->llc[0] = WLAN_LLC_DSAP_FIELD; |
105 | Header->llc[1] = WLAN_LLC_SSAP_FIELD; | 89 | Header->llc[1] = WLAN_LLC_SSAP_FIELD; |
106 | 90 | Header->llc[2] = 0; // FIXME | |
91 | Header->llc[3] = 0; // FIXME | ||
107 | return GNUNET_YES; | 92 | return GNUNET_YES; |
108 | } | 93 | } |
109 | 94 | ||
@@ -112,13 +97,10 @@ int | |||
112 | main (int argc, char *argv[]) | 97 | main (int argc, char *argv[]) |
113 | { | 98 | { |
114 | char msg_buf[WLAN_MTU]; | 99 | char msg_buf[WLAN_MTU]; |
115 | struct GNUNET_MessageHeader *msg; | 100 | struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radiotap; |
116 | struct ieee80211_frame *wlan_header; | ||
117 | struct Radiotap_Send *radiotap; | ||
118 | |||
119 | unsigned int temp[6]; | 101 | unsigned int temp[6]; |
120 | char inmac[6]; | 102 | struct GNUNET_TRANSPORT_WLAN_MacAddress inmac; |
121 | char outmac[6]; | 103 | struct GNUNET_TRANSPORT_WLAN_MacAddress outmac; |
122 | int pos; | 104 | int pos; |
123 | long long count; | 105 | long long count; |
124 | double bytes_per_s; | 106 | double bytes_per_s; |
@@ -144,6 +126,8 @@ main (int argc, char *argv[]) | |||
144 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); | 126 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); |
145 | return 1; | 127 | return 1; |
146 | } | 128 | } |
129 | for (i = 0; i < 6; i++) | ||
130 | outmac.mac[i] = temp[i]; | ||
147 | if (6 != | 131 | if (6 != |
148 | SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], | 132 | SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], |
149 | &temp[3], &temp[4], &temp[5])) | 133 | &temp[3], &temp[4], &temp[5])) |
@@ -154,9 +138,7 @@ main (int argc, char *argv[]) | |||
154 | return 1; | 138 | return 1; |
155 | } | 139 | } |
156 | for (i = 0; i < 6; i++) | 140 | for (i = 0; i < 6; i++) |
157 | inmac[i] = temp[i]; | 141 | inmac.mac[i] = temp[i]; |
158 | for (i = 0; i < 6; i++) | ||
159 | outmac[i] = temp[i]; | ||
160 | 142 | ||
161 | pid_t pid; | 143 | pid_t pid; |
162 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ | 144 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ |
@@ -185,22 +167,16 @@ main (int argc, char *argv[]) | |||
185 | setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ | 167 | setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ |
186 | 168 | ||
187 | 169 | ||
188 | msg = (struct GNUNET_MessageHeader *) msg_buf; | 170 | radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; |
189 | msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 171 | getRadiotapHeader (radiotap, WLAN_MTU); |
190 | msg->size = htons (WLAN_MTU); | ||
191 | radiotap = (struct Radiotap_Send *) &msg[1]; | ||
192 | wlan_header = (struct ieee80211_frame *) &radiotap[1]; | ||
193 | pos = 0; | 172 | pos = 0; |
194 | 173 | getWlanHeader (&radiotap->frame, &outmac, &inmac, | |
195 | getRadiotapHeader (radiotap); | 174 | WLAN_MTU); |
196 | getWlanHeader (wlan_header, outmac, inmac, | ||
197 | WLAN_MTU - sizeof (struct GNUNET_MessageHeader)); | ||
198 | |||
199 | start = time (NULL); | 175 | start = time (NULL); |
200 | count = 0; | 176 | count = 0; |
201 | while (1) | 177 | while (1) |
202 | { | 178 | { |
203 | pos += write (commpipe[1], msg, WLAN_MTU - pos); | 179 | pos += write (commpipe[1], msg_buf, WLAN_MTU - pos); |
204 | if (pos % WLAN_MTU == 0) | 180 | if (pos % WLAN_MTU == 0) |
205 | { | 181 | { |
206 | pos = 0; | 182 | pos = 0; |