ozprotocol.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /* -----------------------------------------------------------------------------
  2. * Copyright (c) 2011 Ozmo Inc
  3. * Released under the GNU General Public License Version 2 (GPLv2).
  4. * -----------------------------------------------------------------------------
  5. */
  6. #ifndef _OZPROTOCOL_H
  7. #define _OZPROTOCOL_H
  8. #define PACKED __packed
  9. #define OZ_ETHERTYPE 0x892e
  10. /* Status codes
  11. */
  12. #define OZ_STATUS_SUCCESS 0
  13. #define OZ_STATUS_INVALID_PARAM 1
  14. #define OZ_STATUS_TOO_MANY_PDS 2
  15. #define OZ_STATUS_NOT_ALLOWED 4
  16. #define OZ_STATUS_SESSION_MISMATCH 5
  17. #define OZ_STATUS_SESSION_TEARDOWN 6
  18. /* This is the generic element header.
  19. Every element starts with this.
  20. */
  21. struct oz_elt {
  22. u8 type;
  23. u8 length;
  24. } PACKED;
  25. #define oz_next_elt(__elt) \
  26. (struct oz_elt *)((u8 *)((__elt) + 1) + (__elt)->length)
  27. /* Protocol element IDs.
  28. */
  29. #define OZ_ELT_CONNECT_REQ 0x06
  30. #define OZ_ELT_CONNECT_RSP 0x07
  31. #define OZ_ELT_DISCONNECT 0x08
  32. #define OZ_ELT_UPDATE_PARAM_REQ 0x11
  33. #define OZ_ELT_FAREWELL_REQ 0x12
  34. #define OZ_ELT_APP_DATA 0x31
  35. /* This is the Ozmo header which is the first Ozmo specific part
  36. * of a frame and comes after the MAC header.
  37. */
  38. struct oz_hdr {
  39. u8 control;
  40. u8 last_pkt_num;
  41. u32 pkt_num;
  42. } PACKED;
  43. #define OZ_PROTOCOL_VERSION 0x1
  44. /* Bits in the control field. */
  45. #define OZ_VERSION_MASK 0xc
  46. #define OZ_VERSION_SHIFT 2
  47. #define OZ_F_ACK 0x10
  48. #define OZ_F_ISOC 0x20
  49. #define OZ_F_MORE_DATA 0x40
  50. #define OZ_F_ACK_REQUESTED 0x80
  51. #define oz_get_prot_ver(__x) (((__x) & OZ_VERSION_MASK) >> OZ_VERSION_SHIFT)
  52. /* Used to select the bits of packet number to put in the last_pkt_num.
  53. */
  54. #define OZ_LAST_PN_MASK 0x00ff
  55. #define OZ_LAST_PN_HALF_CYCLE 127
  56. #define OZ_LATENCY_MASK 0xc0
  57. #define OZ_ONE_MS_LATENCY 0x40
  58. #define OZ_TEN_MS_LATENCY 0x80
  59. /* Connect request data structure.
  60. */
  61. struct oz_elt_connect_req {
  62. u8 mode;
  63. u8 resv1[16];
  64. u8 pd_info;
  65. u8 session_id;
  66. u8 presleep;
  67. u8 ms_isoc_latency;
  68. u8 host_vendor;
  69. u8 keep_alive;
  70. u16 apps;
  71. u8 max_len_div16;
  72. u8 ms_per_isoc;
  73. u8 resv3[2];
  74. } PACKED;
  75. /* mode field bits.
  76. */
  77. #define OZ_MODE_POLLED 0x0
  78. #define OZ_MODE_TRIGGERED 0x1
  79. #define OZ_MODE_MASK 0xf
  80. #define OZ_F_ISOC_NO_ELTS 0x40
  81. #define OZ_F_ISOC_ANYTIME 0x80
  82. #define OZ_NO_ELTS_ANYTIME 0xc0
  83. /* Keep alive field.
  84. */
  85. #define OZ_KALIVE_TYPE_MASK 0xc0
  86. #define OZ_KALIVE_VALUE_MASK 0x3f
  87. #define OZ_KALIVE_SPECIAL 0x00
  88. #define OZ_KALIVE_SECS 0x40
  89. #define OZ_KALIVE_MINS 0x80
  90. #define OZ_KALIVE_HOURS 0xc0
  91. /* Connect response data structure.
  92. */
  93. struct oz_elt_connect_rsp {
  94. u8 mode;
  95. u8 status;
  96. u8 resv1[3];
  97. u8 session_id;
  98. u16 apps;
  99. u32 resv2;
  100. } PACKED;
  101. struct oz_elt_farewell {
  102. u8 ep_num;
  103. u8 index;
  104. u8 report[1];
  105. } PACKED;
  106. struct oz_elt_update_param {
  107. u8 resv1[16];
  108. u8 presleep;
  109. u8 resv2;
  110. u8 host_vendor;
  111. u8 keepalive;
  112. } PACKED;
  113. /* Header common to all application elements.
  114. */
  115. struct oz_app_hdr {
  116. u8 app_id;
  117. u8 elt_seq_num;
  118. } PACKED;
  119. /* Values for app_id.
  120. */
  121. #define OZ_APPID_USB 0x1
  122. #define OZ_APPID_SERIAL 0x4
  123. #define OZ_APPID_MAX OZ_APPID_SERIAL
  124. #define OZ_NB_APPS (OZ_APPID_MAX+1)
  125. /* USB header common to all elements for the USB application.
  126. * This header extends the oz_app_hdr and comes directly after
  127. * the element header in a USB application.
  128. */
  129. struct oz_usb_hdr {
  130. u8 app_id;
  131. u8 elt_seq_num;
  132. u8 type;
  133. } PACKED;
  134. /* USB requests element subtypes (type field of hs_usb_hdr).
  135. */
  136. #define OZ_GET_DESC_REQ 1
  137. #define OZ_GET_DESC_RSP 2
  138. #define OZ_SET_CONFIG_REQ 3
  139. #define OZ_SET_CONFIG_RSP 4
  140. #define OZ_SET_INTERFACE_REQ 5
  141. #define OZ_SET_INTERFACE_RSP 6
  142. #define OZ_VENDOR_CLASS_REQ 7
  143. #define OZ_VENDOR_CLASS_RSP 8
  144. #define OZ_GET_STATUS_REQ 9
  145. #define OZ_GET_STATUS_RSP 10
  146. #define OZ_CLEAR_FEATURE_REQ 11
  147. #define OZ_CLEAR_FEATURE_RSP 12
  148. #define OZ_SET_FEATURE_REQ 13
  149. #define OZ_SET_FEATURE_RSP 14
  150. #define OZ_GET_CONFIGURATION_REQ 15
  151. #define OZ_GET_CONFIGURATION_RSP 16
  152. #define OZ_GET_INTERFACE_REQ 17
  153. #define OZ_GET_INTERFACE_RSP 18
  154. #define OZ_SYNCH_FRAME_REQ 19
  155. #define OZ_SYNCH_FRAME_RSP 20
  156. #define OZ_USB_ENDPOINT_DATA 23
  157. #define OZ_REQD_D2H 0x80
  158. struct oz_get_desc_req {
  159. u8 app_id;
  160. u8 elt_seq_num;
  161. u8 type;
  162. u8 req_id;
  163. u16 offset;
  164. u16 size;
  165. u8 req_type;
  166. u8 desc_type;
  167. __le16 w_index;
  168. u8 index;
  169. } PACKED;
  170. /* Values for desc_type field.
  171. */
  172. #define OZ_DESC_DEVICE 0x01
  173. #define OZ_DESC_CONFIG 0x02
  174. #define OZ_DESC_STRING 0x03
  175. /* Values for req_type field.
  176. */
  177. #define OZ_RECP_MASK 0x1F
  178. #define OZ_RECP_DEVICE 0x00
  179. #define OZ_RECP_INTERFACE 0x01
  180. #define OZ_RECP_ENDPOINT 0x02
  181. #define OZ_REQT_MASK 0x60
  182. #define OZ_REQT_STD 0x00
  183. #define OZ_REQT_CLASS 0x20
  184. #define OZ_REQT_VENDOR 0x40
  185. struct oz_get_desc_rsp {
  186. u8 app_id;
  187. u8 elt_seq_num;
  188. u8 type;
  189. u8 req_id;
  190. __le16 offset;
  191. __le16 total_size;
  192. u8 rcode;
  193. u8 data[1];
  194. } PACKED;
  195. struct oz_feature_req {
  196. u8 app_id;
  197. u8 elt_seq_num;
  198. u8 type;
  199. u8 req_id;
  200. u8 recipient;
  201. u8 index;
  202. u16 feature;
  203. } PACKED;
  204. struct oz_feature_rsp {
  205. u8 app_id;
  206. u8 elt_seq_num;
  207. u8 type;
  208. u8 req_id;
  209. u8 rcode;
  210. } PACKED;
  211. struct oz_set_config_req {
  212. u8 app_id;
  213. u8 elt_seq_num;
  214. u8 type;
  215. u8 req_id;
  216. u8 index;
  217. } PACKED;
  218. struct oz_set_config_rsp {
  219. u8 app_id;
  220. u8 elt_seq_num;
  221. u8 type;
  222. u8 req_id;
  223. u8 rcode;
  224. } PACKED;
  225. struct oz_set_interface_req {
  226. u8 app_id;
  227. u8 elt_seq_num;
  228. u8 type;
  229. u8 req_id;
  230. u8 index;
  231. u8 alternative;
  232. } PACKED;
  233. struct oz_set_interface_rsp {
  234. u8 app_id;
  235. u8 elt_seq_num;
  236. u8 type;
  237. u8 req_id;
  238. u8 rcode;
  239. } PACKED;
  240. struct oz_get_interface_req {
  241. u8 app_id;
  242. u8 elt_seq_num;
  243. u8 type;
  244. u8 req_id;
  245. u8 index;
  246. } PACKED;
  247. struct oz_get_interface_rsp {
  248. u8 app_id;
  249. u8 elt_seq_num;
  250. u8 type;
  251. u8 req_id;
  252. u8 rcode;
  253. u8 alternative;
  254. } PACKED;
  255. struct oz_vendor_class_req {
  256. u8 app_id;
  257. u8 elt_seq_num;
  258. u8 type;
  259. u8 req_id;
  260. u8 req_type;
  261. u8 request;
  262. u16 value;
  263. u16 index;
  264. u8 data[1];
  265. } PACKED;
  266. struct oz_vendor_class_rsp {
  267. u8 app_id;
  268. u8 elt_seq_num;
  269. u8 type;
  270. u8 req_id;
  271. u8 rcode;
  272. u8 data[1];
  273. } PACKED;
  274. struct oz_data {
  275. u8 app_id;
  276. u8 elt_seq_num;
  277. u8 type;
  278. u8 endpoint;
  279. u8 format;
  280. } PACKED;
  281. struct oz_isoc_fixed {
  282. u8 app_id;
  283. u8 elt_seq_num;
  284. u8 type;
  285. u8 endpoint;
  286. u8 format;
  287. u8 unit_size;
  288. u8 frame_number;
  289. u8 data[1];
  290. } PACKED;
  291. struct oz_multiple_fixed {
  292. u8 app_id;
  293. u8 elt_seq_num;
  294. u8 type;
  295. u8 endpoint;
  296. u8 format;
  297. u8 unit_size;
  298. u8 data[1];
  299. } PACKED;
  300. struct oz_fragmented {
  301. u8 app_id;
  302. u8 elt_seq_num;
  303. u8 type;
  304. u8 endpoint;
  305. u8 format;
  306. u16 total_size;
  307. u16 offset;
  308. u8 data[1];
  309. } PACKED;
  310. /* Note: the following does not get packaged in an element in the same way
  311. * that other data formats are packaged. Instead the data is put in a frame
  312. * directly after the oz_header and is the only permitted data in such a
  313. * frame. The length of the data is directly determined from the frame size.
  314. */
  315. struct oz_isoc_large {
  316. u8 endpoint;
  317. u8 format;
  318. u8 ms_data;
  319. u8 frame_number;
  320. } PACKED;
  321. #define OZ_DATA_F_TYPE_MASK 0xF
  322. #define OZ_DATA_F_MULTIPLE_FIXED 0x1
  323. #define OZ_DATA_F_MULTIPLE_VAR 0x2
  324. #define OZ_DATA_F_ISOC_FIXED 0x3
  325. #define OZ_DATA_F_ISOC_VAR 0x4
  326. #define OZ_DATA_F_FRAGMENTED 0x5
  327. #define OZ_DATA_F_ISOC_LARGE 0x7
  328. #endif /* _OZPROTOCOL_H */