wlp-internal.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * WiMedia Logical Link Control Protocol (WLP)
  3. * Internal API
  4. *
  5. * Copyright (C) 2007 Intel Corporation
  6. * Reinette Chatre <reinette.chatre@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. */
  23. #ifndef __WLP_INTERNAL_H__
  24. #define __WLP_INTERNAL_H__
  25. /**
  26. * State of WSS connection
  27. *
  28. * A device needs to connect to a neighbor in an activated WSS before data
  29. * can be transmitted. The spec also distinguishes between a new connection
  30. * attempt and a connection attempt after previous connection attempts. The
  31. * state WLP_WSS_CONNECT_FAILED is used for this scenario. See WLP 0.99
  32. * [7.2.6]
  33. */
  34. enum wlp_wss_connect {
  35. WLP_WSS_UNCONNECTED = 0,
  36. WLP_WSS_CONNECTED,
  37. WLP_WSS_CONNECT_FAILED,
  38. };
  39. extern struct kobj_type wss_ktype;
  40. extern struct attribute_group wss_attr_group;
  41. /* This should be changed to a dynamic array where entries are sorted
  42. * by eth_addr and search is done in a binary form
  43. *
  44. * Although thinking twice about it: this technologie's maximum reach
  45. * is 10 meters...unless you want to pack too much stuff in around
  46. * your radio controller/WLP device, the list will probably not be
  47. * too big.
  48. *
  49. * In any case, there is probably some data structure in the kernel
  50. * than we could reused for that already.
  51. *
  52. * The below structure is really just good while we support one WSS per
  53. * host.
  54. */
  55. struct wlp_eda_node {
  56. struct list_head list_node;
  57. unsigned char eth_addr[ETH_ALEN];
  58. struct uwb_dev_addr dev_addr;
  59. struct wlp_wss *wss;
  60. unsigned char virt_addr[ETH_ALEN];
  61. u8 tag;
  62. enum wlp_wss_connect state;
  63. };
  64. typedef int (*wlp_eda_for_each_f)(struct wlp *, struct wlp_eda_node *, void *);
  65. extern void wlp_eda_init(struct wlp_eda *);
  66. extern void wlp_eda_release(struct wlp_eda *);
  67. extern int wlp_eda_create_node(struct wlp_eda *,
  68. const unsigned char eth_addr[ETH_ALEN],
  69. const struct uwb_dev_addr *);
  70. extern void wlp_eda_rm_node(struct wlp_eda *, const struct uwb_dev_addr *);
  71. extern int wlp_eda_update_node(struct wlp_eda *,
  72. const struct uwb_dev_addr *,
  73. struct wlp_wss *,
  74. const unsigned char virt_addr[ETH_ALEN],
  75. const u8, const enum wlp_wss_connect);
  76. extern int wlp_eda_update_node_state(struct wlp_eda *,
  77. const struct uwb_dev_addr *,
  78. const enum wlp_wss_connect);
  79. extern int wlp_copy_eda_node(struct wlp_eda *, struct uwb_dev_addr *,
  80. struct wlp_eda_node *);
  81. extern int wlp_eda_for_each(struct wlp_eda *, wlp_eda_for_each_f , void *);
  82. extern int wlp_eda_for_virtual(struct wlp_eda *,
  83. const unsigned char eth_addr[ETH_ALEN],
  84. struct uwb_dev_addr *,
  85. wlp_eda_for_each_f , void *);
  86. extern void wlp_remove_neighbor_tmp_info(struct wlp_neighbor_e *);
  87. extern size_t wlp_wss_key_print(char *, size_t, u8 *);
  88. /* Function called when no more references to WSS exists */
  89. extern void wlp_wss_release(struct kobject *);
  90. extern void wlp_wss_reset(struct wlp_wss *);
  91. extern int wlp_wss_create_activate(struct wlp_wss *, struct wlp_uuid *,
  92. char *, unsigned, unsigned);
  93. extern int wlp_wss_enroll_activate(struct wlp_wss *, struct wlp_uuid *,
  94. struct uwb_dev_addr *);
  95. extern ssize_t wlp_discover(struct wlp *);
  96. extern int wlp_enroll_neighbor(struct wlp *, struct wlp_neighbor_e *,
  97. struct wlp_wss *, struct wlp_uuid *);
  98. extern int wlp_wss_is_active(struct wlp *, struct wlp_wss *,
  99. struct uwb_dev_addr *);
  100. struct wlp_assoc_conn_ctx {
  101. struct work_struct ws;
  102. struct wlp *wlp;
  103. struct sk_buff *skb;
  104. struct wlp_eda_node eda_entry;
  105. };
  106. extern int wlp_wss_connect_prep(struct wlp *, struct wlp_eda_node *, void *);
  107. extern int wlp_wss_send_copy(struct wlp *, struct wlp_eda_node *, void *);
  108. /* Message handling */
  109. struct wlp_assoc_frame_ctx {
  110. struct work_struct ws;
  111. struct wlp *wlp;
  112. struct sk_buff *skb;
  113. struct uwb_dev_addr src;
  114. };
  115. extern int wlp_wss_prep_hdr(struct wlp *, struct wlp_eda_node *, void *);
  116. extern void wlp_handle_d1_frame(struct work_struct *);
  117. extern int wlp_parse_d2_frame_to_cache(struct wlp *, struct sk_buff *,
  118. struct wlp_neighbor_e *);
  119. extern int wlp_parse_d2_frame_to_enroll(struct wlp_wss *, struct sk_buff *,
  120. struct wlp_neighbor_e *,
  121. struct wlp_uuid *);
  122. extern void wlp_handle_c1_frame(struct work_struct *);
  123. extern void wlp_handle_c3_frame(struct work_struct *);
  124. extern int wlp_parse_c3c4_frame(struct wlp *, struct sk_buff *,
  125. struct wlp_uuid *, u8 *,
  126. struct uwb_mac_addr *);
  127. extern int wlp_parse_f0(struct wlp *, struct sk_buff *);
  128. extern int wlp_send_assoc_frame(struct wlp *, struct wlp_wss *,
  129. struct uwb_dev_addr *, enum wlp_assoc_type);
  130. extern ssize_t wlp_get_version(struct wlp *, struct wlp_attr_version *,
  131. u8 *, ssize_t);
  132. extern ssize_t wlp_get_wssid(struct wlp *, struct wlp_attr_wssid *,
  133. struct wlp_uuid *, ssize_t);
  134. extern int __wlp_alloc_device_info(struct wlp *);
  135. extern int __wlp_setup_device_info(struct wlp *);
  136. extern struct wlp_wss_attribute wss_attribute_properties;
  137. extern struct wlp_wss_attribute wss_attribute_members;
  138. extern struct wlp_wss_attribute wss_attribute_state;
  139. static inline
  140. size_t wlp_wss_uuid_print(char *buf, size_t bufsize, struct wlp_uuid *uuid)
  141. {
  142. size_t result;
  143. result = scnprintf(buf, bufsize,
  144. "%02x:%02x:%02x:%02x:%02x:%02x:"
  145. "%02x:%02x:%02x:%02x:%02x:%02x:"
  146. "%02x:%02x:%02x:%02x",
  147. uuid->data[0], uuid->data[1],
  148. uuid->data[2], uuid->data[3],
  149. uuid->data[4], uuid->data[5],
  150. uuid->data[6], uuid->data[7],
  151. uuid->data[8], uuid->data[9],
  152. uuid->data[10], uuid->data[11],
  153. uuid->data[12], uuid->data[13],
  154. uuid->data[14], uuid->data[15]);
  155. return result;
  156. }
  157. /**
  158. * FIXME: How should a nonce be displayed?
  159. */
  160. static inline
  161. size_t wlp_wss_nonce_print(char *buf, size_t bufsize, struct wlp_nonce *nonce)
  162. {
  163. size_t result;
  164. result = scnprintf(buf, bufsize,
  165. "%02x %02x %02x %02x %02x %02x "
  166. "%02x %02x %02x %02x %02x %02x "
  167. "%02x %02x %02x %02x",
  168. nonce->data[0], nonce->data[1],
  169. nonce->data[2], nonce->data[3],
  170. nonce->data[4], nonce->data[5],
  171. nonce->data[6], nonce->data[7],
  172. nonce->data[8], nonce->data[9],
  173. nonce->data[10], nonce->data[11],
  174. nonce->data[12], nonce->data[13],
  175. nonce->data[14], nonce->data[15]);
  176. return result;
  177. }
  178. static inline
  179. void wlp_session_cb(struct wlp *wlp)
  180. {
  181. struct completion *completion = wlp->session->cb_priv;
  182. complete(completion);
  183. }
  184. static inline
  185. int wlp_uuid_is_set(struct wlp_uuid *uuid)
  186. {
  187. struct wlp_uuid zero_uuid = { .data = { 0x00, 0x00, 0x00, 0x00,
  188. 0x00, 0x00, 0x00, 0x00,
  189. 0x00, 0x00, 0x00, 0x00,
  190. 0x00, 0x00, 0x00, 0x00} };
  191. if (!memcmp(uuid, &zero_uuid, sizeof(*uuid)))
  192. return 0;
  193. return 1;
  194. }
  195. #endif /* __WLP_INTERNAL_H__ */