ps3_gelic_wireless.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * PS3 gelic network driver.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2007 Sony Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation version 2.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _GELIC_WIRELESS_H
  21. #define _GELIC_WIRELESS_H
  22. #include <linux/wireless.h>
  23. #include <net/iw_handler.h>
  24. /* return value from GELIC_LV1_GET_WLAN_EVENT netcontrol */
  25. enum gelic_lv1_wl_event {
  26. GELIC_LV1_WL_EVENT_DEVICE_READY = 0x01, /* Eurus ready */
  27. GELIC_LV1_WL_EVENT_SCAN_COMPLETED = 0x02, /* Scan has completed */
  28. GELIC_LV1_WL_EVENT_DEAUTH = 0x04, /* Deauthed by the AP */
  29. GELIC_LV1_WL_EVENT_BEACON_LOST = 0x08, /* Beacon lost detected */
  30. GELIC_LV1_WL_EVENT_CONNECTED = 0x10, /* Connected to AP */
  31. GELIC_LV1_WL_EVENT_WPA_CONNECTED = 0x20, /* WPA connection */
  32. GELIC_LV1_WL_EVENT_WPA_ERROR = 0x40, /* MIC error */
  33. };
  34. /* arguments for GELIC_LV1_POST_WLAN_COMMAND netcontrol */
  35. enum gelic_eurus_command {
  36. GELIC_EURUS_CMD_ASSOC = 1, /* association start */
  37. GELIC_EURUS_CMD_DISASSOC = 2, /* disassociate */
  38. GELIC_EURUS_CMD_START_SCAN = 3, /* scan start */
  39. GELIC_EURUS_CMD_GET_SCAN = 4, /* get scan result */
  40. GELIC_EURUS_CMD_SET_COMMON_CFG = 5, /* set common config */
  41. GELIC_EURUS_CMD_GET_COMMON_CFG = 6, /* set common config */
  42. GELIC_EURUS_CMD_SET_WEP_CFG = 7, /* set WEP config */
  43. GELIC_EURUS_CMD_GET_WEP_CFG = 8, /* get WEP config */
  44. GELIC_EURUS_CMD_SET_WPA_CFG = 9, /* set WPA config */
  45. GELIC_EURUS_CMD_GET_WPA_CFG = 10, /* get WPA config */
  46. GELIC_EURUS_CMD_GET_RSSI_CFG = 11, /* get RSSI info. */
  47. GELIC_EURUS_CMD_MAX_INDEX
  48. };
  49. /* for GELIC_EURUS_CMD_COMMON_CFG */
  50. enum gelic_eurus_bss_type {
  51. GELIC_EURUS_BSS_INFRA = 0,
  52. GELIC_EURUS_BSS_ADHOC = 1, /* not supported */
  53. };
  54. enum gelic_eurus_auth_method {
  55. GELIC_EURUS_AUTH_OPEN = 0, /* FIXME: WLAN_AUTH_OPEN */
  56. GELIC_EURUS_AUTH_SHARED = 1, /* not supported */
  57. };
  58. enum gelic_eurus_opmode {
  59. GELIC_EURUS_OPMODE_11BG = 0, /* 802.11b/g */
  60. GELIC_EURUS_OPMODE_11B = 1, /* 802.11b only */
  61. GELIC_EURUS_OPMODE_11G = 2, /* 802.11g only */
  62. };
  63. struct gelic_eurus_common_cfg {
  64. /* all fields are big endian */
  65. u16 scan_index;
  66. u16 bss_type; /* infra or adhoc */
  67. u16 auth_method; /* shared key or open */
  68. u16 op_mode; /* B/G */
  69. } __packed;
  70. /* for GELIC_EURUS_CMD_WEP_CFG */
  71. enum gelic_eurus_wep_security {
  72. GELIC_EURUS_WEP_SEC_NONE = 0,
  73. GELIC_EURUS_WEP_SEC_40BIT = 1,
  74. GELIC_EURUS_WEP_SEC_104BIT = 2,
  75. };
  76. struct gelic_eurus_wep_cfg {
  77. /* all fields are big endian */
  78. u16 security;
  79. u8 key[4][16];
  80. } __packed;
  81. /* for GELIC_EURUS_CMD_WPA_CFG */
  82. enum gelic_eurus_wpa_security {
  83. GELIC_EURUS_WPA_SEC_NONE = 0x0000,
  84. /* group=TKIP, pairwise=TKIP */
  85. GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP = 0x0001,
  86. /* group=AES, pairwise=AES */
  87. GELIC_EURUS_WPA_SEC_WPA_AES_AES = 0x0002,
  88. /* group=TKIP, pairwise=TKIP */
  89. GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP = 0x0004,
  90. /* group=AES, pairwise=AES */
  91. GELIC_EURUS_WPA_SEC_WPA2_AES_AES = 0x0008,
  92. /* group=TKIP, pairwise=AES */
  93. GELIC_EURUS_WPA_SEC_WPA_TKIP_AES = 0x0010,
  94. /* group=TKIP, pairwise=AES */
  95. GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES = 0x0020,
  96. };
  97. enum gelic_eurus_wpa_psk_type {
  98. GELIC_EURUS_WPA_PSK_PASSPHRASE = 0, /* passphrase string */
  99. GELIC_EURUS_WPA_PSK_BIN = 1, /* 32 bytes binary key */
  100. };
  101. #define GELIC_WL_EURUS_PSK_MAX_LEN 64
  102. #define WPA_PSK_LEN 32 /* WPA spec says 256bit */
  103. struct gelic_eurus_wpa_cfg {
  104. /* all fields are big endian */
  105. u16 security;
  106. u16 psk_type; /* psk key encoding type */
  107. u8 psk[GELIC_WL_EURUS_PSK_MAX_LEN]; /* psk key; hex or passphrase */
  108. } __packed;
  109. /* for GELIC_EURUS_CMD_{START,GET}_SCAN */
  110. enum gelic_eurus_scan_capability {
  111. GELIC_EURUS_SCAN_CAP_ADHOC = 0x0000,
  112. GELIC_EURUS_SCAN_CAP_INFRA = 0x0001,
  113. GELIC_EURUS_SCAN_CAP_MASK = 0x0001,
  114. };
  115. enum gelic_eurus_scan_sec_type {
  116. GELIC_EURUS_SCAN_SEC_NONE = 0x0000,
  117. GELIC_EURUS_SCAN_SEC_WEP = 0x0100,
  118. GELIC_EURUS_SCAN_SEC_WPA = 0x0200,
  119. GELIC_EURUS_SCAN_SEC_WPA2 = 0x0400,
  120. GELIC_EURUS_SCAN_SEC_MASK = 0x0f00,
  121. };
  122. enum gelic_eurus_scan_sec_wep_type {
  123. GELIC_EURUS_SCAN_SEC_WEP_UNKNOWN = 0x0000,
  124. GELIC_EURUS_SCAN_SEC_WEP_40 = 0x0001,
  125. GELIC_EURUS_SCAN_SEC_WEP_104 = 0x0002,
  126. GELIC_EURUS_SCAN_SEC_WEP_MASK = 0x0003,
  127. };
  128. enum gelic_eurus_scan_sec_wpa_type {
  129. GELIC_EURUS_SCAN_SEC_WPA_UNKNOWN = 0x0000,
  130. GELIC_EURUS_SCAN_SEC_WPA_TKIP = 0x0001,
  131. GELIC_EURUS_SCAN_SEC_WPA_AES = 0x0002,
  132. GELIC_EURUS_SCAN_SEC_WPA_MASK = 0x0003,
  133. };
  134. /*
  135. * hw BSS information structure returned from GELIC_EURUS_CMD_GET_SCAN
  136. */
  137. struct gelic_eurus_scan_info {
  138. /* all fields are big endian */
  139. __be16 size;
  140. __be16 rssi; /* percentage */
  141. __be16 channel; /* channel number */
  142. __be16 beacon_period; /* FIXME: in msec unit */
  143. __be16 capability;
  144. __be16 security;
  145. u8 bssid[8]; /* last ETH_ALEN are valid. bssid[0],[1] are unused */
  146. u8 essid[32]; /* IW_ESSID_MAX_SIZE */
  147. u8 rate[16]; /* first 12 are valid */
  148. u8 ext_rate[16]; /* first 16 are valid */
  149. __be32 reserved1;
  150. __be32 reserved2;
  151. __be32 reserved3;
  152. __be32 reserved4;
  153. u8 elements[0]; /* ie */
  154. } __packed;
  155. /* the hypervisor returns bbs up to 16 */
  156. #define GELIC_EURUS_MAX_SCAN (16)
  157. struct gelic_wl_scan_info {
  158. struct list_head list;
  159. struct gelic_eurus_scan_info *hwinfo;
  160. int valid; /* set 1 if this entry was in latest scanned list
  161. * from Eurus */
  162. unsigned int eurus_index; /* index in the Eurus list */
  163. unsigned long last_scanned; /* acquired time */
  164. unsigned int rate_len;
  165. unsigned int rate_ext_len;
  166. unsigned int essid_len;
  167. };
  168. /* for GELIC_EURUS_CMD_GET_RSSI */
  169. struct gelic_eurus_rssi_info {
  170. /* big endian */
  171. __be16 rssi;
  172. } __packed;
  173. /* for 'stat' member of gelic_wl_info */
  174. enum gelic_wl_info_status_bit {
  175. GELIC_WL_STAT_CONFIGURED,
  176. GELIC_WL_STAT_CH_INFO, /* ch info acquired */
  177. GELIC_WL_STAT_ESSID_SET, /* ESSID specified by userspace */
  178. GELIC_WL_STAT_BSSID_SET, /* BSSID specified by userspace */
  179. GELIC_WL_STAT_WPA_PSK_SET, /* PMK specified by userspace */
  180. GELIC_WL_STAT_WPA_LEVEL_SET, /* WEP or WPA[2] selected */
  181. };
  182. /* for 'scan_stat' member of gelic_wl_info */
  183. enum gelic_wl_scan_state {
  184. /* just initialized or get last scan result failed */
  185. GELIC_WL_SCAN_STAT_INIT,
  186. /* scan request issued, accepted or chip is scanning */
  187. GELIC_WL_SCAN_STAT_SCANNING,
  188. /* scan results retrieved */
  189. GELIC_WL_SCAN_STAT_GOT_LIST,
  190. };
  191. /* for 'cipher_method' */
  192. enum gelic_wl_cipher_method {
  193. GELIC_WL_CIPHER_NONE,
  194. GELIC_WL_CIPHER_WEP,
  195. GELIC_WL_CIPHER_TKIP,
  196. GELIC_WL_CIPHER_AES,
  197. };
  198. /* for 'wpa_level' */
  199. enum gelic_wl_wpa_level {
  200. GELIC_WL_WPA_LEVEL_NONE,
  201. GELIC_WL_WPA_LEVEL_WPA,
  202. GELIC_WL_WPA_LEVEL_WPA2,
  203. };
  204. /* for 'assoc_stat' */
  205. enum gelic_wl_assoc_state {
  206. GELIC_WL_ASSOC_STAT_DISCONN,
  207. GELIC_WL_ASSOC_STAT_ASSOCIATING,
  208. GELIC_WL_ASSOC_STAT_ASSOCIATED,
  209. };
  210. /* part of private data alloc_etherdev() allocated */
  211. #define GELIC_WEP_KEYS 4
  212. struct gelic_wl_info {
  213. /* bss list */
  214. struct mutex scan_lock;
  215. struct list_head network_list;
  216. struct list_head network_free_list;
  217. struct gelic_wl_scan_info *networks;
  218. unsigned long scan_age; /* last scanned time */
  219. enum gelic_wl_scan_state scan_stat;
  220. struct completion scan_done;
  221. /* eurus command queue */
  222. struct workqueue_struct *eurus_cmd_queue;
  223. struct completion cmd_done_intr;
  224. /* eurus event handling */
  225. struct workqueue_struct *event_queue;
  226. struct delayed_work event_work;
  227. /* wl status bits */
  228. unsigned long stat;
  229. enum gelic_eurus_auth_method auth_method; /* open/shared */
  230. enum gelic_wl_cipher_method group_cipher_method;
  231. enum gelic_wl_cipher_method pairwise_cipher_method;
  232. enum gelic_wl_wpa_level wpa_level; /* wpa/wpa2 */
  233. /* association handling */
  234. struct mutex assoc_stat_lock;
  235. struct delayed_work assoc_work;
  236. enum gelic_wl_assoc_state assoc_stat;
  237. struct completion assoc_done;
  238. spinlock_t lock;
  239. u16 ch_info; /* available channels. bit0 = ch1 */
  240. /* WEP keys */
  241. u8 key[GELIC_WEP_KEYS][IW_ENCODING_TOKEN_MAX];
  242. unsigned long key_enabled;
  243. unsigned int key_len[GELIC_WEP_KEYS];
  244. unsigned int current_key;
  245. /* WWPA PSK */
  246. u8 psk[GELIC_WL_EURUS_PSK_MAX_LEN];
  247. enum gelic_eurus_wpa_psk_type psk_type;
  248. unsigned int psk_len;
  249. u8 essid[IW_ESSID_MAX_SIZE];
  250. u8 bssid[ETH_ALEN]; /* userland requested */
  251. u8 active_bssid[ETH_ALEN]; /* associated bssid */
  252. unsigned int essid_len;
  253. struct iw_public_data wireless_data;
  254. struct iw_statistics iwstat;
  255. };
  256. #define GELIC_WL_BSS_MAX_ENT 32
  257. #define GELIC_WL_ASSOC_RETRY 50
  258. static inline struct gelic_port *wl_port(struct gelic_wl_info *wl)
  259. {
  260. return container_of((void *)wl, struct gelic_port, priv);
  261. }
  262. static inline struct gelic_wl_info *port_wl(struct gelic_port *port)
  263. {
  264. return port_priv(port);
  265. }
  266. struct gelic_eurus_cmd {
  267. struct work_struct work;
  268. struct gelic_wl_info *wl;
  269. unsigned int cmd; /* command code */
  270. u64 tag;
  271. u64 size;
  272. void *buffer;
  273. unsigned int buf_size;
  274. struct completion done;
  275. int status;
  276. u64 cmd_status;
  277. };
  278. /* private ioctls to pass PSK */
  279. #define GELIC_WL_PRIV_SET_PSK (SIOCIWFIRSTPRIV + 0)
  280. #define GELIC_WL_PRIV_GET_PSK (SIOCIWFIRSTPRIV + 1)
  281. int gelic_wl_driver_probe(struct gelic_card *card);
  282. int gelic_wl_driver_remove(struct gelic_card *card);
  283. void gelic_wl_interrupt(struct net_device *netdev, u64 status);
  284. #endif /* _GELIC_WIRELESS_H */