xref: /netbsd/sys/dev/usb/mbim.h (revision 2f30fca2)
1 /*	$NetBSD: mbim.h,v 1.2 2021/08/26 21:33:36 andvar Exp $ */
2 /*	$OpenBSD: mbim.h,v 1.4 2017/04/18 13:27:55 gerhard Exp $ */
3 
4 /*
5  * Copyright (c) 2016 genua mbH
6  * All rights reserved.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /*
22  * Mobile Broadband Interface Model
23  * http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
24  */
25 #ifndef _MBIM_H_
26 #define _MBIM_H_
27 
28 #define UDESCSUB_MBIM			27
29 #define MBIM_INTERFACE_ALTSETTING	1
30 
31 #define MBIM_RESET_FUNCTION		0x05
32 
33 /*
34  * Registration state (MBIM_REGISTER_STATE)
35  */
36 #define MBIM_REGSTATE_UNKNOWN			0
37 #define MBIM_REGSTATE_DEREGISTERED		1
38 #define MBIM_REGSTATE_SEARCHING			2
39 #define MBIM_REGSTATE_HOME			3
40 #define MBIM_REGSTATE_ROAMING			4
41 #define MBIM_REGSTATE_PARTNER			5
42 #define MBIM_REGSTATE_DENIED			6
43 
44 /*
45  * Data classes mask (MBIM_DATA_CLASS)
46  */
47 #define MBIM_DATACLASS_NONE			0x00000000
48 #define MBIM_DATACLASS_GPRS			0x00000001
49 #define MBIM_DATACLASS_EDGE			0x00000002
50 #define MBIM_DATACLASS_UMTS			0x00000004
51 #define MBIM_DATACLASS_HSDPA			0x00000008
52 #define MBIM_DATACLASS_HSUPA			0x00000010
53 #define MBIM_DATACLASS_LTE			0x00000020
54 #define MBIM_DATACLASS_1XRTT			0x00010000
55 #define MBIM_DATACLASS_1XEVDO			0x00020000
56 #define MBIM_DATACLASS_1XEVDO_REV_A		0x00040000
57 #define MBIM_DATACLASS_1XEVDV			0x00080000
58 #define MBIM_DATACLASS_3XRTT			0x00100000
59 #define MBIM_DATACLASS_1XEVDO_REV_B		0x00200000
60 #define MBIM_DATACLASS_UMB			0x00400000
61 #define MBIM_DATACLASS_CUSTOM			0x80000000
62 
63 /*
64  * Cell classes mask (MBIM_CELLULAR_CLASS)
65  */
66 #define MBIM_CELLCLASS_GSM			0x00000001
67 #define MBIM_CELLCLASS_CDMA			0x00000002
68 
69 /*
70  * UUIDs
71  */
72 #define MBIM_UUID_LEN		16
73 
74 #define MBIM_UUID_BASIC_CONNECT {				\
75 		0xa2, 0x89, 0xcc, 0x33, 0xbc, 0xbb, 0x8b, 0x4f,	\
76 		0xb6, 0xb0, 0x13, 0x3e, 0xc2, 0xaa, 0xe6, 0xdf	\
77 	}
78 
79 #define MBIM_UUID_CONTEXT_INTERNET {				\
80 		0x7e, 0x5e, 0x2a, 0x7e, 0x4e, 0x6f, 0x72, 0x72,	\
81 		0x73, 0x6b, 0x65, 0x6e, 0x7e, 0x5e, 0x2a, 0x7e	\
82 	}
83 
84 #define MBIM_UUID_CONTEXT_VPN {				\
85 		0x9b, 0x9f, 0x7b, 0xbe, 0x89, 0x52, 0x44, 0xb7,	\
86 		0x83, 0xac, 0xca, 0x41, 0x31, 0x8d, 0xf7, 0xa0	\
87 	}
88 
89 #define MBIM_UUID_QMI_MBIM {				\
90 		0xd1, 0xa3, 0x0b, 0xc2, 0xf9, 0x7a, 0x6e, 0x43,	\
91 		0xbf, 0x65, 0xc7, 0xe2, 0x4f, 0xb0, 0xf0, 0xd3	\
92 	}
93 
94 #define MBIM_CTRLMSG_MINLEN		64
95 #define MBIM_CTRLMSG_MAXLEN		(4 * 1204)
96 
97 #define MBIM_MAXSEGSZ_MINVAL		(2 * 1024)
98 
99 /*
100  * Control messages (host to function)
101  */
102 #define MBIM_OPEN_MSG			1U
103 #define MBIM_CLOSE_MSG			2U
104 #define MBIM_COMMAND_MSG		3U
105 #define MBIM_HOST_ERROR_MSG		4U
106 
107 /*
108  * Control messages (function to host)
109  */
110 #define MBIM_OPEN_DONE			0x80000001U
111 #define MBIM_CLOSE_DONE			0x80000002U
112 #define MBIM_COMMAND_DONE		0x80000003U
113 #define MBIM_FUNCTION_ERROR_MSG		0x80000004U
114 #define MBIM_INDICATE_STATUS_MSG	0x80000007U
115 
116 /*
117  * Generic status codes
118  */
119 #define MBIM_STATUS_SUCCESS			0
120 #define MBIM_STATUS_BUSY			1
121 #define MBIM_STATUS_FAILURE			2
122 #define MBIM_STATUS_SIM_NOT_INSERTED		3
123 #define MBIM_STATUS_BAD_SIM			4
124 #define MBIM_STATUS_PIN_REQUIRED		5
125 #define MBIM_STATUS_PIN_DISABLED		6
126 #define MBIM_STATUS_NOT_REGISTERED		7
127 #define MBIM_STATUS_PROVIDERS_NOT_FOUND		8
128 #define MBIM_STATUS_NO_DEVICE_SUPPORT		9
129 #define MBIM_STATUS_PROVIDER_NOT_VISIBLE	10
130 #define MBIM_STATUS_DATA_CLASS_NOT_AVAILABLE	11
131 #define MBIM_STATUS_PACKET_SERVICE_DETACHED	12
132 #define MBIM_STATUS_MAX_ACTIVATED_CONTEXTS	13
133 #define MBIM_STATUS_NOT_INITIALIZED		14
134 #define MBIM_STATUS_VOICE_CALL_IN_PROGRESS	15
135 #define MBIM_STATUS_CONTEXT_NOT_ACTIVATED	16
136 #define MBIM_STATUS_SERVICE_NOT_ACTIVATED	17
137 #define MBIM_STATUS_INVALID_ACCESS_STRING	18
138 #define MBIM_STATUS_INVALID_USER_NAME_PWD	19
139 #define MBIM_STATUS_RADIO_POWER_OFF		20
140 #define MBIM_STATUS_INVALID_PARAMETERS		21
141 #define MBIM_STATUS_READ_FAILURE		22
142 #define MBIM_STATUS_WRITE_FAILURE		23
143 #define MBIM_STATUS_NO_PHONEBOOK		25
144 #define MBIM_STATUS_PARAMETER_TOO_LONG		26
145 #define MBIM_STATUS_STK_BUSY			27
146 #define MBIM_STATUS_OPERATION_NOT_ALLOWED	28
147 #define MBIM_STATUS_MEMORY_FAILURE		29
148 #define MBIM_STATUS_INVALID_MEMORY_INDEX	30
149 #define MBIM_STATUS_MEMORY_FULL			31
150 #define MBIM_STATUS_FILTER_NOT_SUPPORTED	32
151 #define MBIM_STATUS_DSS_INSTANCE_LIMIT		33
152 #define MBIM_STATUS_INVALID_DEVICE_SERVICE_OPERATION	34
153 #define MBIM_STATUS_AUTH_INCORRECT_AUTN		35
154 #define MBIM_STATUS_AUTH_SYNC_FAILURE		36
155 #define MBIM_STATUS_AUTH_AMF_NOT_SET		37
156 #define MBIM_STATUS_CONTEXT_NOT_SUPPORTED	38
157 #define MBIM_STATUS_SMS_UNKNOWN_SMSC_ADDRESS	100
158 #define MBIM_STATUS_SMS_NETWORK_TIMEOUT		101
159 #define MBIM_STATUS_SMS_LANG_NOT_SUPPORTED	102
160 #define MBIM_STATUS_SMS_ENCODING_NOT_SUPPORTED	103
161 #define MBIM_STATUS_SMS_FORMAT_NOT_SUPPORTED	104
162 
163 /*
164  * Message formats
165  */
166 struct mbim_msghdr {
167 	/* Msg header */
168 	uint32_t	type;		/* message type */
169 	uint32_t	len;		/* message length */
170 	uint32_t	tid;		/* transaction id */
171 } __packed;
172 
173 struct mbim_fraghdr {
174 	uint32_t	nfrag;		/* total # of fragments */
175 	uint32_t	currfrag;	/* current fragment */
176 } __packed;
177 
178 struct mbim_fragmented_msg_hdr {
179 	struct mbim_msghdr	hdr;
180 	struct mbim_fraghdr	frag;
181 } __packed;
182 
183 struct mbim_h2f_openmsg {
184 	struct mbim_msghdr	hdr;
185 	uint32_t		maxlen;
186 } __packed;
187 
188 struct mbim_h2f_closemsg {
189 	struct mbim_msghdr	hdr;
190 } __packed;
191 
192 struct mbim_h2f_cmd {
193 	struct mbim_msghdr	hdr;
194 	struct mbim_fraghdr	frag;
195 	uint8_t			devid[MBIM_UUID_LEN];
196 	uint32_t		cid;		/* command id */
197 #define MBIM_CMDOP_QRY		0
198 #define MBIM_CMDOP_SET		1
199 	uint32_t		op;
200 	uint32_t		infolen;
201 	uint8_t			info[];
202 } __packed;
203 
204 struct mbim_f2h_indicate_status {
205 	struct mbim_msghdr	hdr;
206 	struct mbim_fraghdr	frag;
207 	uint8_t			devid[MBIM_UUID_LEN];
208 	uint32_t		cid;		/* command id */
209 	uint32_t		infolen;
210 	uint8_t			info[];
211 } __packed;
212 
213 struct mbim_f2h_hosterr {
214 	struct mbim_msghdr	hdr;
215 
216 #define MBIM_ERROR_TIMEOUT_FRAGMENT		1
217 #define MBIM_ERROR_FRAGMENT_OUT_OF_SEQUENCE	2
218 #define MBIM_ERROR_LENGTH_MISMATCH		3
219 #define MBIM_ERROR_DUPLICATED_TID		4
220 #define MBIM_ERROR_NOT_OPENED			5
221 #define MBIM_ERROR_UNKNOWN			6
222 #define MBIM_ERROR_CANCEL			7
223 #define MBIM_ERROR_MAX_TRANSFER			8
224 	uint32_t		err;
225 } __packed;
226 
227 struct mbim_f2h_openclosedone {
228 	struct mbim_msghdr	hdr;
229 	int32_t			status;
230 } __packed;
231 
232 struct mbim_f2h_cmddone {
233 	struct mbim_msghdr	hdr;
234 	struct mbim_fraghdr	frag;
235 	uint8_t			devid[MBIM_UUID_LEN];
236 	uint32_t		cid;		/* command id */
237 	int32_t			status;
238 	uint32_t		infolen;
239 	uint8_t			info[];
240 } __packed;
241 
242 /*
243  * Messages and commands for MBIM_UUID_BASIC_CONNECT
244  */
245 #define MBIM_CID_DEVICE_CAPS				1
246 #define MBIM_CID_SUBSCRIBER_READY_STATUS		2
247 #define MBIM_CID_RADIO_STATE				3
248 #define MBIM_CID_PIN					4
249 #define MBIM_CID_PIN_LIST				5
250 #define MBIM_CID_HOME_PROVIDER				6
251 #define MBIM_CID_PREFERRED_PROVIDERS			7
252 #define MBIM_CID_VISIBLE_PROVIDERS			8
253 #define MBIM_CID_REGISTER_STATE				9
254 #define MBIM_CID_PACKET_SERVICE				10
255 #define MBIM_CID_SIGNAL_STATE				11
256 #define MBIM_CID_CONNECT				12
257 #define MBIM_CID_PROVISIONED_CONTEXTS			13
258 #define MBIM_CID_SERVICE_ACTIVATION			14
259 #define MBIM_CID_IP_CONFIGURATION			15
260 #define MBIM_CID_DEVICE_SERVICES			16
261 #define MBIM_CID_DEVICE_SERVICE_SUBSCRIBE_LIST		19
262 #define MBIM_CID_PACKET_STATISTICS			20
263 #define MBIM_CID_NETWORK_IDLE_HINT			21
264 #define MBIM_CID_EMERGENCY_MODE				22
265 #define MBIM_CID_IP_PACKET_FILTERS			23
266 #define MBIM_CID_MULTICARRIER_PROVIDERS			24
267 
268 struct mbim_cid_subscriber_ready_info {
269 #define MBIM_SIMSTATE_NOTINITIALIZED		0
270 #define MBIM_SIMSTATE_INITIALIZED		1
271 #define MBIM_SIMSTATE_NOTINSERTED		2
272 #define MBIM_SIMSTATE_BADSIM			3
273 #define MBIM_SIMSTATE_FAILURE			4
274 #define MBIM_SIMSTATE_NOTACTIVATED		5
275 #define MBIM_SIMSTATE_LOCKED			6
276 	uint32_t	ready;
277 
278 	uint32_t	sid_offs;
279 	uint32_t	sid_size;
280 
281 	uint32_t	icc_offs;
282 	uint32_t	icc_size;
283 
284 #define MBIM_SIMUNIQEID_NONE			0
285 #define MBIM_SIMUNIQEID_PROTECT			1
286 	uint32_t	info;
287 
288 	uint32_t	no_pn;
289 	struct {
290 		uint32_t	offs;
291 		uint32_t	size;
292 	}
293 			pn[];
294 } __packed;
295 
296 struct mbim_cid_radio_state {
297 #define MBIM_RADIO_STATE_OFF			0
298 #define MBIM_RADIO_STATE_ON			1
299 	uint32_t	state;
300 } __packed;
301 
302 struct mbim_cid_radio_state_info {
303 	uint32_t	hw_state;
304 	uint32_t	sw_state;
305 } __packed;
306 
307 struct mbim_cid_pin {
308 #define MBIM_PIN_TYPE_NONE			0
309 #define MBIM_PIN_TYPE_CUSTOM			1
310 #define MBIM_PIN_TYPE_PIN1			2
311 #define MBIM_PIN_TYPE_PIN2			3
312 #define MBIM_PIN_TYPE_DEV_SIM_PIN		4
313 #define MBIM_PIN_TYPE_DEV_FIRST_SIM_PIN		5
314 #define MBIM_PIN_TYPE_NETWORK_PIN		6
315 #define MBIM_PIN_TYPE_NETWORK_SUBSET_PIN	7
316 #define MBIM_PIN_TYPE_SERVICE_PROVIDER_PIN	8
317 #define MBIM_PIN_TYPE_CORPORATE_PIN		9
318 #define MBIM_PIN_TYPE_SUBSIDY_LOCK		10
319 #define MBIM_PIN_TYPE_PUK1			11
320 #define MBIM_PIN_TYPE_PUK2			12
321 #define MBIM_PIN_TYPE_DEV_FIRST_SIM_PUK		13
322 #define MBIM_PIN_TYPE_NETWORK_PUK		14
323 #define MBIM_PIN_TYPE_NETWORK_SUBSET_PUK	15
324 #define MBIM_PIN_TYPE_SERVICE_PROVIDER_PUK	16
325 #define MBIM_PIN_TYPE_CORPORATE_PUK		17
326 	uint32_t	type;
327 
328 #define MBIM_PIN_OP_ENTER			0
329 #define MBIM_PIN_OP_ENABLE			1
330 #define MBIM_PIN_OP_DISABLE			2
331 #define MBIM_PIN_OP_CHANGE			3
332 	uint32_t	op;
333 	uint32_t	pin_offs;
334 	uint32_t	pin_size;
335 	uint32_t	newpin_offs;
336 	uint32_t	newpin_size;
337 #define MBIM_PIN_MAXLEN	32
338 	uint8_t		data[2 * MBIM_PIN_MAXLEN];
339 } __packed;
340 
341 struct mbim_cid_pin_info {
342 	uint32_t	type;
343 
344 #define MBIM_PIN_STATE_UNLOCKED			0
345 #define MBIM_PIN_STATE_LOCKED			1
346 	uint32_t	state;
347 	uint32_t	remaining_attempts;
348 } __packed;
349 
350 struct mbim_cid_pin_list_info {
351 	struct mbim_pin_desc {
352 
353 #define MBIM_PINMODE_NOTSUPPORTED		0
354 #define MBIM_PINMODE_ENABLED			1
355 #define MBIM_PINMODE_DISABLED			2
356 		uint32_t	mode;
357 
358 #define MBIM_PINFORMAT_UNKNOWN			0
359 #define MBIM_PINFORMAT_NUMERIC			1
360 #define MBIM_PINFORMAT_ALPHANUMERIC		2
361 		uint32_t	format;
362 
363 		uint32_t	minlen;
364 		uint32_t	maxlen;
365 	}
366 		pin1,
367 		pin2,
368 		dev_sim_pin,
369 		first_dev_sim_pin,
370 		net_pin,
371 		net_sub_pin,
372 		svp_pin,
373 		corp_pin,
374 		subsidy_lock,
375 		custom;
376 } __packed;
377 
378 struct mbim_cid_device_caps {
379 #define MBIM_DEVTYPE_UNKNOWN			0
380 #define MBIM_DEVTYPE_EMBEDDED			1
381 #define MBIM_DEVTYPE_REMOVABLE			2
382 #define MBIM_DEVTYPE_REMOTE			3
383 	uint32_t	devtype;
384 
385 	uint32_t	cellclass;	/* values: MBIM_CELLULAR_CLASS */
386 	uint32_t	voiceclass;
387 	uint32_t	simclass;
388 	uint32_t	dataclass;	/* values: MBIM_DATA_CLASS */
389 	uint32_t	smscaps;
390 	uint32_t	cntrlcaps;
391 	uint32_t	max_sessions;
392 
393 	uint32_t	custdataclass_offs;
394 	uint32_t	custdataclass_size;
395 
396 	uint32_t	devid_offs;
397 	uint32_t	devid_size;
398 
399 	uint32_t	fwinfo_offs;
400 	uint32_t	fwinfo_size;
401 
402 	uint32_t	hwinfo_offs;
403 	uint32_t	hwinfo_size;
404 
405 	uint32_t	data[];
406 } __packed;
407 
408 struct mbim_cid_registration_state {
409 	uint32_t	provid_offs;
410 	uint32_t	provid_size;
411 
412 #define MBIM_REGACTION_AUTOMATIC		0
413 #define MBIM_REGACTION_MANUAL			1
414 	uint32_t	regaction;
415 	uint32_t	data_class;
416 
417 	uint32_t	data[];
418 } __packed;
419 
420 struct mbim_cid_registration_state_info {
421 	uint32_t	nwerror;
422 
423 	uint32_t	regstate;	/* values: MBIM_REGISTER_STATE */
424 
425 #define MBIM_REGMODE_UNKNOWN			0
426 #define MBIM_REGMODE_AUTOMATIC			1
427 #define MBIM_REGMODE_MANUAL			2
428 	uint32_t	regmode;
429 
430 	uint32_t	availclasses;	/* values: MBIM_DATA_CLASS */
431 	uint32_t	curcellclass;	/* values: MBIM_CELLULAR_CLASS */
432 
433 	uint32_t	provid_offs;
434 	uint32_t	provid_size;
435 
436 	uint32_t	provname_offs;
437 	uint32_t	provname_size;
438 
439 	uint32_t	roamingtxt_offs;
440 	uint32_t	roamingtxt_size;
441 
442 #define MBIM_REGFLAGS_NONE			0
443 #define MBIM_REGFLAGS_MANUAL_NOT_AVAILABLE	1
444 #define MBIM_REGFLAGS_PACKETSERVICE_AUTOATTACH	2
445 	uint32_t	regflag;
446 
447 	uint32_t	data[];
448 } __packed;
449 
450 struct mbim_cid_packet_service {
451 #define MBIM_PKTSERVICE_ACTION_ATTACH		0
452 #define MBIM_PKTSERVICE_ACTION_DETACH		1
453 	uint32_t	action;
454 } __packed;
455 
456 struct mbim_cid_packet_service_info {
457 	uint32_t	nwerror;
458 
459 #define MBIM_PKTSERVICE_STATE_UNKNOWN		0
460 #define MBIM_PKTSERVICE_STATE_ATTACHING		1
461 #define MBIM_PKTSERVICE_STATE_ATTACHED		2
462 #define MBIM_PKTSERVICE_STATE_DETACHING		3
463 #define MBIM_PKTSERVICE_STATE_DETACHED		4
464 	uint32_t	state;
465 
466 	uint32_t	highest_dataclass;
467 	uint64_t	uplink_speed;
468 	uint64_t	downlink_speed;
469 } __packed;
470 
471 struct mbim_cid_signal_state {
472 	uint32_t	rssi;
473 	uint32_t	err_rate;
474 	uint32_t	ss_intvl;
475 	uint32_t	rssi_thr;
476 	uint32_t	err_thr;
477 } __packed;
478 
479 struct mbim_cid_connect {
480 	uint32_t	sessionid;
481 
482 #define MBIM_CONNECT_DEACTIVATE		0
483 #define MBIM_CONNECT_ACTIVATE		1
484 	uint32_t	command;
485 
486 #define MBIM_ACCESS_MAXLEN		200
487 	uint32_t	access_offs;
488 	uint32_t	access_size;
489 
490 #define MBIM_USER_MAXLEN		510
491 	uint32_t	user_offs;
492 	uint32_t	user_size;
493 
494 #define MBIM_PASSWD_MAXLEN		510
495 	uint32_t	passwd_offs;
496 	uint32_t	passwd_size;
497 
498 #define MBIM_COMPRESSION_NONE		0
499 #define MBIM_COMPRESSION_ENABLE		1
500 	uint32_t	compression;
501 
502 #define MBIM_AUTHPROT_NONE		0
503 #define MBIM_AUTHPROT_PAP		1
504 #define MBIM_AUTHPROT_CHAP		2
505 #define MBIM_AUTHPROT_MSCHAP		3
506 	uint32_t	authprot;
507 
508 #define MBIM_CONTEXT_IPTYPE_DEFAULT	0
509 #define MBIM_CONTEXT_IPTYPE_IPV4	1
510 #define MBIM_CONTEXT_IPTYPE_IPV6	2
511 #define MBIM_CONTEXT_IPTYPE_IPV4V6	3
512 #define MBIM_CONTEXT_IPTYPE_IPV4ANDV6	4
513 	uint32_t	iptype;
514 
515 	uint8_t		context[MBIM_UUID_LEN];
516 
517 	uint8_t		data[MBIM_ACCESS_MAXLEN + MBIM_USER_MAXLEN +
518 			     MBIM_PASSWD_MAXLEN];
519 
520 } __packed;
521 
522 struct mbim_cid_connect_info {
523 	uint32_t	sessionid;
524 
525 #define MBIM_ACTIVATION_STATE_UNKNOWN		0
526 #define MBIM_ACTIVATION_STATE_ACTIVATED		1
527 #define MBIM_ACTIVATION_STATE_ACTIVATING	2
528 #define MBIM_ACTIVATION_STATE_DEACTIVATED	3
529 #define MBIM_ACTIVATION_STATE_DEACTIVATING	4
530 	uint32_t	activation;
531 
532 	uint32_t	voice;
533 	uint32_t	iptype;
534 	uint8_t		context[MBIM_UUID_LEN];
535 	uint32_t	nwerror;
536 } __packed;
537 
538 struct mbim_cid_ipv4_element {
539 	uint32_t	prefixlen;
540 	uint32_t	addr;
541 } __packed;
542 
543 struct mbim_cid_ipv6_element {
544 	uint32_t	prefixlen;
545 	uint8_t		addr[16];
546 } __packed;
547 
548 struct mbim_cid_ip_configuration_info {
549 	uint32_t	sessionid;
550 
551 #define MBIM_IPCONF_HAS_ADDRINFO	0x0001
552 #define MBIM_IPCONF_HAS_GWINFO		0x0002
553 #define MBIM_IPCONF_HAS_DNSINFO		0x0004
554 #define MBIM_IPCONF_HAS_MTUINFO		0x0008
555 	uint32_t	ipv4_available;
556 	uint32_t	ipv6_available;
557 
558 	uint32_t	ipv4_naddr;
559 	uint32_t	ipv4_addroffs;
560 	uint32_t	ipv6_naddr;
561 	uint32_t	ipv6_addroffs;
562 
563 	uint32_t	ipv4_gwoffs;
564 	uint32_t	ipv6_gwoffs;
565 
566 	uint32_t	ipv4_ndnssrv;
567 	uint32_t	ipv4_dnssrvoffs;
568 	uint32_t	ipv6_ndnssrv;
569 	uint32_t	ipv6_dnssrvoffs;
570 
571 	uint32_t	ipv4_mtu;
572 	uint32_t	ipv6_mtu;
573 
574 	uint32_t	data[];
575 } __packed;
576 
577 struct mbim_cid_packet_statistics_info {
578 	uint32_t	in_discards;
579 	uint32_t	in_errors;
580 	uint64_t	in_octets;
581 	uint64_t	in_packets;
582 	uint64_t	out_octets;
583 	uint64_t	out_packets;
584 	uint32_t	out_errors;
585 	uint32_t	out_discards;
586 } __packed;
587 
588 
589 #ifdef _KERNEL
590 
591 struct mbim_descriptor {
592 	uByte	bLength;
593 	uByte	bDescriptorType;
594 	uByte	bDescriptorSubtype;
595 #define MBIM_VER_MAJOR(v)	(((v) >> 8) & 0x0f)
596 #define MBIM_VER_MINOR(v)	((v) & 0x0f)
597 	uWord	bcdMBIMVersion;
598 	uWord	wMaxControlMessage;
599 	uByte	bNumberFilters;
600 	uByte	bMaxFilterSize;
601 	uWord	wMaxSegmentSize;
602 	uByte	bmNetworkCapabilities;
603 } __packed;
604 
605 /*
606  * NCM Parameters
607  */
608 #define NCM_GET_NTB_PARAMETERS	0x80
609 
610 struct ncm_ntb_parameters {
611 	uWord	wLength;
612 	uWord	bmNtbFormatsSupported;
613 #define NCM_FORMAT_NTB16	0x0001
614 #define NCM_FORMAT_NTB32	0x0002
615 	uDWord	dwNtbInMaxSize;
616 	uWord	wNtbInDivisor;
617 	uWord	wNtbInPayloadRemainder;
618 	uWord	wNtbInAlignment;
619 	uWord	wReserved1;
620 	uDWord	dwNtbOutMaxSize;
621 	uWord	wNtbOutDivisor;
622 	uWord	wNtbOutPayloadRemainder;
623 	uWord	wNtbOutAlignment;
624 	uWord	wNtbOutMaxDatagrams;
625 } __packed;
626 
627 /*
628  * NCM Encoding
629  */
630 #define MBIM_HDR16_LEN	\
631 	(sizeof(struct ncm_header16) + sizeof(struct ncm_pointer16))
632 #define MBIM_HDR32_LEN	\
633 	(sizeof(struct ncm_header32) + sizeof(struct ncm_pointer32))
634 
635 struct ncm_header16 {
636 #define NCM_HDR16_SIG		0x484d434e
637 	uDWord	dwSignature;
638 	uWord	wHeaderLength;
639 	uWord	wSequence;
640 	uWord	wBlockLength;
641 	uWord	wNdpIndex;
642 } __packed;
643 
644 struct ncm_header32 {
645 #define NCM_HDR32_SIG		0x686d636e
646 	uDWord	dwSignature;
647 	uWord	wHeaderLength;
648 	uWord	wSequence;
649 	uDWord	dwBlockLength;
650 	uDWord	dwNdpIndex;
651 } __packed;
652 
653 
654 #define MBIM_NCM_NTH_SIDSHIFT	24
655 #define MBIM_NCM_NTH_GETSID(s)	(((s) > MBIM_NCM_NTH_SIDSHIFT) & 0xff)
656 
657 struct ncm_pointer16_dgram {
658 	uWord	wDatagramIndex;
659 	uWord	wDatagramLen;
660 } __packed;
661 
662 struct ncm_pointer16 {
663 #define MBIM_NCM_NTH16_IPS	 0x00535049
664 #define MBIM_NCM_NTH16_ISISG(s) (((s) & 0x00ffffff) == MBIM_NCM_NTH16_IPS)
665 #define MBIM_NCM_NTH16_SIG(s)	\
666 		((((s) & 0xff) << MBIM_NCM_NTH_SIDSHIFT) | MBIM_NCM_NTH16_IPS)
667 	uDWord	dwSignature;
668 	uWord	wLength;
669 	uWord	wNextNdpIndex;
670 
671 	/* Minimum is two datagrams, but can be more */
672 	struct ncm_pointer16_dgram dgram[2];
673 } __packed;
674 
675 struct ncm_pointer32_dgram {
676 	uDWord	dwDatagramIndex;
677 	uDWord	dwDatagramLen;
678 } __packed;
679 
680 struct ncm_pointer32 {
681 #define MBIM_NCM_NTH32_IPS	0x00737069
682 #define MBIM_NCM_NTH32_ISISG(s)	\
683 		(((s) & 0x00ffffff) == MBIM_NCM_NTH32_IPS)
684 #define MBIM_NCM_NTH32_SIG(s)		\
685 		((((s) & 0xff) << MBIM_NCM_NTH_SIDSHIFT) | MBIM_NCM_NTH32_IPS)
686 	uDWord	dwSignature;
687 	uWord	wLength;
688 	uWord	wReserved6;
689 	uDWord	dwNextNdpIndex;
690 	uDWord	dwReserved12;
691 
692 	/* Minimum is two datagrams, but can be more */
693 	struct ncm_pointer32_dgram dgram[2];
694 } __packed;
695 
696 #endif /* _KERNEL */
697 
698 #endif /* _MBIM_H_ */
699