plugin_transport_wlan.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2010, 2011 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file transport/plugin_transport_wlan.h
  18. * @brief header for transport plugin and the helper for wlan
  19. * @author David Brodski
  20. */
  21. #ifndef PLUGIN_TRANSPORT_WLAN
  22. #define PLUGIN_TRANSPORT_WLAN
  23. #include "gnunet_crypto_lib.h"
  24. #include "gnunet_common.h"
  25. /**
  26. * Number fo bytes in a mac address.
  27. */
  28. #ifdef MINGW
  29. #define MAC_ADDR_SIZE 8
  30. typedef uint8_t u_int8_t;
  31. #else
  32. #define MAC_ADDR_SIZE 6
  33. #endif
  34. /**
  35. * Value for "Management" in the 'frame_control' field of the
  36. * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
  37. */
  38. #define IEEE80211_FC0_TYPE_MGT 0x00
  39. /**
  40. * Value for "Control" in the 'frame_control' field of the
  41. * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
  42. */
  43. #define IEEE80211_FC0_TYPE_CTL 0x04
  44. /**
  45. * Value for DATA in the 'frame_control' field of the
  46. * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
  47. */
  48. #define IEEE80211_FC0_TYPE_DATA 0x08
  49. GNUNET_NETWORK_STRUCT_BEGIN
  50. /**
  51. * A MAC Address.
  52. */
  53. struct GNUNET_TRANSPORT_WLAN_MacAddress
  54. {
  55. uint8_t mac[MAC_ADDR_SIZE];
  56. };
  57. /**
  58. * Format of a WLAN Control Message.
  59. */
  60. struct GNUNET_TRANSPORT_WLAN_HelperControlMessage
  61. {
  62. /**
  63. * Message header. Type is
  64. * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
  65. */
  66. struct GNUNET_MessageHeader hdr;
  67. /**
  68. * MAC Address of the local WLAN interface.
  69. */
  70. struct GNUNET_TRANSPORT_WLAN_MacAddress mac;
  71. };
  72. /**
  73. * generic definitions for IEEE 802.3 frames
  74. */
  75. struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame
  76. {
  77. /**
  78. * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
  79. */
  80. struct GNUNET_TRANSPORT_WLAN_MacAddress dst;
  81. /**
  82. * Address 2: source address if in ad-hoc-mode or station, BSSID if AP
  83. */
  84. struct GNUNET_TRANSPORT_WLAN_MacAddress src;
  85. /**
  86. * Packet type ID.
  87. */
  88. uint16_t type;
  89. };
  90. /**
  91. * generic definitions for IEEE 802.11 frames
  92. */
  93. struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
  94. {
  95. /**
  96. * 802.11 Frame Control field. A bitmask. The overall field is a
  97. * 16-bit mask of the respecitve fields. The lowest two bits should
  98. * be 0, then comes the "type" (2 bits, see IEEE80211_FC0_TYPE_*
  99. * constants), followed by 4-bit subtype (all zeros for ad-hoc),
  100. * followed by various flags (to DS, from DS, more frag, retry,
  101. * power management, more data, WEP, strict), all of which we also
  102. * keep at zero.
  103. */
  104. uint16_t frame_control GNUNET_PACKED;
  105. /**
  106. * Microseconds to reserve link (duration), 0 by default
  107. */
  108. uint16_t duration GNUNET_PACKED;
  109. /**
  110. * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
  111. */
  112. struct GNUNET_TRANSPORT_WLAN_MacAddress addr1;
  113. /**
  114. * Address 2: source address if in ad-hoc-mode or station, BSSID if AP
  115. */
  116. struct GNUNET_TRANSPORT_WLAN_MacAddress addr2;
  117. /**
  118. * Address 3: BSSID in ad-hoc mode, Destination if station, source if AP
  119. */
  120. struct GNUNET_TRANSPORT_WLAN_MacAddress addr3;
  121. /**
  122. * 802.11 sequence control field; contains fragment number an sequence
  123. * number (we set this to all zeros).
  124. */
  125. uint16_t sequence_control GNUNET_PACKED;
  126. /**
  127. * Link layer control (LLC). Set to a GNUnet-specific value.
  128. */
  129. u_int8_t llc[4];
  130. /* payload */
  131. } GNUNET_PACKED;
  132. /**
  133. * Message from the plugin to the WLAN helper: send the given message with the
  134. * given connection parameters.
  135. */
  136. struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage
  137. {
  138. /**
  139. * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'.
  140. */
  141. struct GNUNET_MessageHeader header;
  142. /**
  143. * wlan send rate
  144. */
  145. uint8_t rate;
  146. /**
  147. * Antenna; the first antenna is 0.
  148. */
  149. uint8_t antenna;
  150. /**
  151. * Transmit power expressed as unitless distance from max power set at factory calibration.
  152. * 0 is max power. Monotonically nondecreasing with lower power levels.
  153. */
  154. uint16_t tx_power GNUNET_PACKED;
  155. /**
  156. * IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not
  157. * trust the plugin to set it correctly).
  158. */
  159. struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
  160. /* actual payload follows */
  161. };
  162. /**
  163. * Message from the WLAN helper to the plugin: we have received the given message with the
  164. * given performance characteristics.
  165. */
  166. /**
  167. * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
  168. */
  169. struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage
  170. {
  171. /**
  172. * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
  173. */
  174. struct GNUNET_MessageHeader header;
  175. /**
  176. * Information about which of the fields below are actually valid.
  177. * 0 for none. FIXME: not properly initialized so far (always zero).
  178. */
  179. uint32_t ri_present GNUNET_PACKED;
  180. /**
  181. * IEEE80211_RADIOTAP_TSFT, 0 if unknown.
  182. */
  183. uint64_t ri_mactime GNUNET_PACKED;
  184. /**
  185. * from radiotap
  186. * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL
  187. * or IEEE80211_RADIOTAP_DB_ANTSIGNAL, 0 if unknown.
  188. */
  189. int32_t ri_power GNUNET_PACKED;
  190. /**
  191. * either IEEE80211_RADIOTAP_DBM_ANTNOISE
  192. * or IEEE80211_RADIOTAP_DB_ANTNOISE, 0 if unknown.
  193. */
  194. int32_t ri_noise GNUNET_PACKED;
  195. /**
  196. * IEEE80211_RADIOTAP_CHANNEL, 0 if unknown.
  197. */
  198. uint32_t ri_channel GNUNET_PACKED;
  199. /**
  200. * Frequency we use. 0 if unknown.
  201. */
  202. uint32_t ri_freq GNUNET_PACKED;
  203. /**
  204. * IEEE80211_RADIOTAP_RATE * 50000, 0 if unknown.
  205. */
  206. uint32_t ri_rate GNUNET_PACKED;
  207. /**
  208. * IEEE80211_RADIOTAP_ANTENNA, 0 if unknown.
  209. */
  210. uint32_t ri_antenna GNUNET_PACKED;
  211. /**
  212. * IEEE Frame.
  213. */
  214. struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
  215. /* followed by payload */
  216. };
  217. GNUNET_NETWORK_STRUCT_END
  218. /**
  219. * GNUnet bssid
  220. */
  221. static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = {
  222. {0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
  223. };
  224. /**
  225. * Broadcast MAC
  226. */
  227. static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = {
  228. {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
  229. };
  230. #endif