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