Line data Source code
1 : /* $OpenBSD: if_umb.h,v 1.4 2017/04/18 13:27:55 gerhard Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2016 genua mbH
5 : * All rights reserved.
6 : *
7 : * Permission to use, copy, modify, and distribute this software for any
8 : * purpose with or without fee is hereby granted, provided that the above
9 : * copyright notice and this permission notice appear in all copies.
10 : *
11 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 : */
19 :
20 : /*
21 : * Mobile Broadband Interface Model
22 : * http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
23 : */
24 :
25 : struct umb_valdescr {
26 : int val;
27 : char *descr;
28 : };
29 :
30 : static const char *
31 0 : umb_val2descr(const struct umb_valdescr *vdp, int val)
32 : {
33 : static char sval[32];
34 :
35 0 : while (vdp->descr != NULL) {
36 0 : if (vdp->val == val)
37 0 : return vdp->descr;
38 0 : vdp++;
39 : }
40 0 : snprintf(sval, sizeof (sval), "#%d", val);
41 0 : return sval;
42 0 : }
43 :
44 : #define MBIM_REGSTATE_DESCRIPTIONS { \
45 : { MBIM_REGSTATE_UNKNOWN, "unknown" }, \
46 : { MBIM_REGSTATE_DEREGISTERED, "not registered" }, \
47 : { MBIM_REGSTATE_SEARCHING, "searching" }, \
48 : { MBIM_REGSTATE_HOME, "home network" }, \
49 : { MBIM_REGSTATE_ROAMING, "roaming network" }, \
50 : { MBIM_REGSTATE_PARTNER, "partner network" }, \
51 : { MBIM_REGSTATE_DENIED, "access denied" }, \
52 : { 0, NULL } }
53 :
54 : #define MBIM_DATACLASS_DESCRIPTIONS { \
55 : { MBIM_DATACLASS_NONE, "none" }, \
56 : { MBIM_DATACLASS_GPRS, "GPRS" }, \
57 : { MBIM_DATACLASS_EDGE, "EDGE" }, \
58 : { MBIM_DATACLASS_UMTS, "UMTS" }, \
59 : { MBIM_DATACLASS_HSDPA, "HSDPA" }, \
60 : { MBIM_DATACLASS_HSUPA, "HSUPA" }, \
61 : { MBIM_DATACLASS_HSDPA|MBIM_DATACLASS_HSUPA, "HSPA" }, \
62 : { MBIM_DATACLASS_LTE, "LTE" }, \
63 : { MBIM_DATACLASS_1XRTT, "CDMA2000" }, \
64 : { MBIM_DATACLASS_1XEVDO, "CDMA2000" }, \
65 : { MBIM_DATACLASS_1XEVDO_REV_A, "CDMA2000" }, \
66 : { MBIM_DATACLASS_1XEVDV, "CDMA2000" }, \
67 : { MBIM_DATACLASS_3XRTT, "CDMA2000" }, \
68 : { MBIM_DATACLASS_1XEVDO_REV_B, "CDMA2000" }, \
69 : { MBIM_DATACLASS_UMB, "CDMA2000" }, \
70 : { MBIM_DATACLASS_CUSTOM, "custom" }, \
71 : { 0, NULL } }
72 :
73 : #define MBIM_1TO1_DESCRIPTION(m) { (m), #m }
74 : #define MBIM_MESSAGES_DESCRIPTIONS { \
75 : MBIM_1TO1_DESCRIPTION(MBIM_OPEN_MSG), \
76 : MBIM_1TO1_DESCRIPTION(MBIM_CLOSE_MSG), \
77 : MBIM_1TO1_DESCRIPTION(MBIM_COMMAND_MSG), \
78 : MBIM_1TO1_DESCRIPTION(MBIM_HOST_ERROR_MSG), \
79 : MBIM_1TO1_DESCRIPTION(MBIM_OPEN_DONE), \
80 : MBIM_1TO1_DESCRIPTION(MBIM_CLOSE_DONE), \
81 : MBIM_1TO1_DESCRIPTION(MBIM_COMMAND_DONE), \
82 : MBIM_1TO1_DESCRIPTION(MBIM_FUNCTION_ERROR_MSG), \
83 : MBIM_1TO1_DESCRIPTION(MBIM_INDICATE_STATUS_MSG), \
84 : { 0, NULL } }
85 :
86 : #define MBIM_STATUS_DESCRIPTION(m) { MBIM_STATUS_ ## m, #m }
87 : #define MBIM_STATUS_DESCRIPTIONS { \
88 : MBIM_STATUS_DESCRIPTION(SUCCESS), \
89 : MBIM_STATUS_DESCRIPTION(BUSY), \
90 : MBIM_STATUS_DESCRIPTION(FAILURE), \
91 : MBIM_STATUS_DESCRIPTION(SIM_NOT_INSERTED), \
92 : MBIM_STATUS_DESCRIPTION(BAD_SIM), \
93 : MBIM_STATUS_DESCRIPTION(PIN_REQUIRED), \
94 : MBIM_STATUS_DESCRIPTION(PIN_DISABLED), \
95 : MBIM_STATUS_DESCRIPTION(NOT_REGISTERED), \
96 : MBIM_STATUS_DESCRIPTION(PROVIDERS_NOT_FOUND), \
97 : MBIM_STATUS_DESCRIPTION(NO_DEVICE_SUPPORT), \
98 : MBIM_STATUS_DESCRIPTION(PROVIDER_NOT_VISIBLE), \
99 : MBIM_STATUS_DESCRIPTION(DATA_CLASS_NOT_AVAILABLE), \
100 : MBIM_STATUS_DESCRIPTION(PACKET_SERVICE_DETACHED), \
101 : MBIM_STATUS_DESCRIPTION(MAX_ACTIVATED_CONTEXTS), \
102 : MBIM_STATUS_DESCRIPTION(NOT_INITIALIZED), \
103 : MBIM_STATUS_DESCRIPTION(VOICE_CALL_IN_PROGRESS), \
104 : MBIM_STATUS_DESCRIPTION(CONTEXT_NOT_ACTIVATED), \
105 : MBIM_STATUS_DESCRIPTION(SERVICE_NOT_ACTIVATED), \
106 : MBIM_STATUS_DESCRIPTION(INVALID_ACCESS_STRING), \
107 : MBIM_STATUS_DESCRIPTION(INVALID_USER_NAME_PWD), \
108 : MBIM_STATUS_DESCRIPTION(RADIO_POWER_OFF), \
109 : MBIM_STATUS_DESCRIPTION(INVALID_PARAMETERS), \
110 : MBIM_STATUS_DESCRIPTION(READ_FAILURE), \
111 : MBIM_STATUS_DESCRIPTION(WRITE_FAILURE), \
112 : MBIM_STATUS_DESCRIPTION(NO_PHONEBOOK), \
113 : MBIM_STATUS_DESCRIPTION(PARAMETER_TOO_LONG), \
114 : MBIM_STATUS_DESCRIPTION(STK_BUSY), \
115 : MBIM_STATUS_DESCRIPTION(OPERATION_NOT_ALLOWED), \
116 : MBIM_STATUS_DESCRIPTION(MEMORY_FAILURE), \
117 : MBIM_STATUS_DESCRIPTION(INVALID_MEMORY_INDEX), \
118 : MBIM_STATUS_DESCRIPTION(MEMORY_FULL), \
119 : MBIM_STATUS_DESCRIPTION(FILTER_NOT_SUPPORTED), \
120 : MBIM_STATUS_DESCRIPTION(DSS_INSTANCE_LIMIT), \
121 : MBIM_STATUS_DESCRIPTION(INVALID_DEVICE_SERVICE_OPERATION), \
122 : MBIM_STATUS_DESCRIPTION(AUTH_INCORRECT_AUTN), \
123 : MBIM_STATUS_DESCRIPTION(AUTH_SYNC_FAILURE), \
124 : MBIM_STATUS_DESCRIPTION(AUTH_AMF_NOT_SET), \
125 : MBIM_STATUS_DESCRIPTION(CONTEXT_NOT_SUPPORTED), \
126 : MBIM_STATUS_DESCRIPTION(SMS_UNKNOWN_SMSC_ADDRESS), \
127 : MBIM_STATUS_DESCRIPTION(SMS_NETWORK_TIMEOUT), \
128 : MBIM_STATUS_DESCRIPTION(SMS_LANG_NOT_SUPPORTED), \
129 : MBIM_STATUS_DESCRIPTION(SMS_ENCODING_NOT_SUPPORTED), \
130 : MBIM_STATUS_DESCRIPTION(SMS_FORMAT_NOT_SUPPORTED), \
131 : { 0, NULL } }
132 :
133 : #define MBIM_ERROR_DESCRIPTION(m) { MBIM_ERROR_ ## m, #m }
134 : #define MBIM_ERROR_DESCRIPTIONS { \
135 : MBIM_ERROR_DESCRIPTION(TIMEOUT_FRAGMENT), \
136 : MBIM_ERROR_DESCRIPTION(FRAGMENT_OUT_OF_SEQUENCE), \
137 : MBIM_ERROR_DESCRIPTION(LENGTH_MISMATCH), \
138 : MBIM_ERROR_DESCRIPTION(DUPLICATED_TID), \
139 : MBIM_ERROR_DESCRIPTION(NOT_OPENED), \
140 : MBIM_ERROR_DESCRIPTION(UNKNOWN), \
141 : MBIM_ERROR_DESCRIPTION(CANCEL), \
142 : MBIM_ERROR_DESCRIPTION(MAX_TRANSFER), \
143 : { 0, NULL } }
144 :
145 : #define MBIM_CID_DESCRIPTIONS { \
146 : MBIM_1TO1_DESCRIPTION(MBIM_CID_DEVICE_CAPS), \
147 : MBIM_1TO1_DESCRIPTION(MBIM_CID_SUBSCRIBER_READY_STATUS), \
148 : MBIM_1TO1_DESCRIPTION(MBIM_CID_RADIO_STATE), \
149 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PIN), \
150 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PIN_LIST), \
151 : MBIM_1TO1_DESCRIPTION(MBIM_CID_HOME_PROVIDER), \
152 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PREFERRED_PROVIDERS), \
153 : MBIM_1TO1_DESCRIPTION(MBIM_CID_VISIBLE_PROVIDERS), \
154 : MBIM_1TO1_DESCRIPTION(MBIM_CID_REGISTER_STATE), \
155 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PACKET_SERVICE), \
156 : MBIM_1TO1_DESCRIPTION(MBIM_CID_SIGNAL_STATE), \
157 : MBIM_1TO1_DESCRIPTION(MBIM_CID_CONNECT), \
158 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PROVISIONED_CONTEXTS), \
159 : MBIM_1TO1_DESCRIPTION(MBIM_CID_SERVICE_ACTIVATION), \
160 : MBIM_1TO1_DESCRIPTION(MBIM_CID_IP_CONFIGURATION), \
161 : MBIM_1TO1_DESCRIPTION(MBIM_CID_DEVICE_SERVICES), \
162 : MBIM_1TO1_DESCRIPTION(MBIM_CID_DEVICE_SERVICE_SUBSCRIBE_LIST), \
163 : MBIM_1TO1_DESCRIPTION(MBIM_CID_PACKET_STATISTICS), \
164 : MBIM_1TO1_DESCRIPTION(MBIM_CID_NETWORK_IDLE_HINT), \
165 : MBIM_1TO1_DESCRIPTION(MBIM_CID_EMERGENCY_MODE), \
166 : MBIM_1TO1_DESCRIPTION(MBIM_CID_IP_PACKET_FILTERS), \
167 : MBIM_1TO1_DESCRIPTION(MBIM_CID_MULTICARRIER_PROVIDERS), \
168 : { 0, NULL } }
169 :
170 : #define MBIM_SIMSTATE_DESCRIPTIONS { \
171 : { MBIM_SIMSTATE_NOTINITIALIZED, "not initialized" }, \
172 : { MBIM_SIMSTATE_INITIALIZED, "initialized" }, \
173 : { MBIM_SIMSTATE_NOTINSERTED, "not inserted" }, \
174 : { MBIM_SIMSTATE_BADSIM, "bad type" }, \
175 : { MBIM_SIMSTATE_FAILURE, "failed" }, \
176 : { MBIM_SIMSTATE_NOTACTIVATED, "not activated" }, \
177 : { MBIM_SIMSTATE_LOCKED, "locked" }, \
178 : { 0, NULL } }
179 :
180 : #define MBIM_PINTYPE_DESCRIPTIONS { \
181 : { MBIM_PIN_TYPE_NONE, "none" }, \
182 : { MBIM_PIN_TYPE_CUSTOM, "custom" }, \
183 : { MBIM_PIN_TYPE_PIN1, "PIN1" }, \
184 : { MBIM_PIN_TYPE_PIN2, "PIN2" }, \
185 : { MBIM_PIN_TYPE_DEV_SIM_PIN, "device PIN" }, \
186 : { MBIM_PIN_TYPE_DEV_FIRST_SIM_PIN, "device 1st PIN" }, \
187 : { MBIM_PIN_TYPE_NETWORK_PIN, "network PIN" }, \
188 : { MBIM_PIN_TYPE_NETWORK_SUBSET_PIN, "network subset PIN" }, \
189 : { MBIM_PIN_TYPE_SERVICE_PROVIDER_PIN, "provider PIN" }, \
190 : { MBIM_PIN_TYPE_CORPORATE_PIN, "corporate PIN" }, \
191 : { MBIM_PIN_TYPE_SUBSIDY_LOCK, "subsidy lock" }, \
192 : { MBIM_PIN_TYPE_PUK1, "PUK" }, \
193 : { MBIM_PIN_TYPE_PUK2, "PUK2" }, \
194 : { MBIM_PIN_TYPE_DEV_FIRST_SIM_PUK, "device 1st PUK" }, \
195 : { MBIM_PIN_TYPE_NETWORK_PUK, "network PUK" }, \
196 : { MBIM_PIN_TYPE_NETWORK_SUBSET_PUK, "network subset PUK" }, \
197 : { MBIM_PIN_TYPE_SERVICE_PROVIDER_PUK, "provider PUK" }, \
198 : { MBIM_PIN_TYPE_CORPORATE_PUK, "corporate PUK" }, \
199 : { 0, NULL } }
200 :
201 : #define MBIM_PKTSRV_STATE_DESCRIPTIONS { \
202 : { MBIM_PKTSERVICE_STATE_UNKNOWN, "unknown" }, \
203 : { MBIM_PKTSERVICE_STATE_ATTACHING, "attaching" }, \
204 : { MBIM_PKTSERVICE_STATE_ATTACHED, "attached" }, \
205 : { MBIM_PKTSERVICE_STATE_DETACHING, "detaching" }, \
206 : { MBIM_PKTSERVICE_STATE_DETACHED, "detached" }, \
207 : { 0, NULL } }
208 :
209 : #define MBIM_ACTIVATION_STATE_DESCRIPTIONS { \
210 : { MBIM_ACTIVATION_STATE_UNKNOWN, "unknown" }, \
211 : { MBIM_ACTIVATION_STATE_ACTIVATED, "activated" }, \
212 : { MBIM_ACTIVATION_STATE_ACTIVATING, "activating" }, \
213 : { MBIM_ACTIVATION_STATE_DEACTIVATED, "deactivated" }, \
214 : { MBIM_ACTIVATION_STATE_DEACTIVATING, "deactivating" }, \
215 : { 0, NULL } }
216 :
217 : /*
218 : * Driver internal state
219 : */
220 : enum umb_state {
221 : UMB_S_DOWN = 0, /* interface down */
222 : UMB_S_OPEN, /* MBIM device has been opened */
223 : UMB_S_CID, /* QMI client id allocated */
224 : UMB_S_RADIO, /* radio is on */
225 : UMB_S_SIMREADY, /* SIM is ready */
226 : UMB_S_ATTACHED, /* packet service is attached */
227 : UMB_S_CONNECTED, /* connected to provider */
228 : UMB_S_UP, /* have IP configuration */
229 : };
230 :
231 : #define UMB_INTERNAL_STATE_DESCRIPTIONS { \
232 : { UMB_S_DOWN, "down" }, \
233 : { UMB_S_OPEN, "open" }, \
234 : { UMB_S_CID, "CID allocated" }, \
235 : { UMB_S_RADIO, "radio on" }, \
236 : { UMB_S_SIMREADY, "SIM is ready" }, \
237 : { UMB_S_ATTACHED, "attached" }, \
238 : { UMB_S_CONNECTED, "connected" }, \
239 : { UMB_S_UP, "up" }, \
240 : { 0, NULL } }
241 :
242 : /*
243 : * UMB parameters (SIOC[GS]UMBPARAM ioctls)
244 : */
245 : struct umb_parameter {
246 : int op;
247 : int is_puk;
248 : char pin[MBIM_PIN_MAXLEN];
249 : int pinlen;
250 :
251 : char newpin[MBIM_PIN_MAXLEN];
252 : int newpinlen;
253 :
254 : #define UMB_APN_MAXLEN 100
255 : uint16_t apn[UMB_APN_MAXLEN];
256 : int apnlen;
257 :
258 : int roaming;
259 : uint32_t preferredclasses;
260 : };
261 :
262 : /*
263 : * UMB device status info (SIOCGUMBINFO ioctl)
264 : */
265 : struct umb_info {
266 : enum umb_state state;
267 : int enable_roaming;
268 : #define UMB_PIN_REQUIRED 0
269 : #define UMB_PIN_UNLOCKED 1
270 : #define UMB_PUK_REQUIRED 2
271 : int pin_state;
272 : int pin_attempts_left;
273 : int activation;
274 : int sim_state;
275 : int regstate;
276 : int regmode;
277 : int nwerror;
278 : int packetstate;
279 : uint32_t supportedclasses; /* what the hw supports */
280 : uint32_t preferredclasses; /* what the user prefers */
281 : uint32_t highestclass; /* what the network offers */
282 : uint32_t cellclass;
283 : #define UMB_PROVIDERNAME_MAXLEN 20
284 : uint16_t provider[UMB_PROVIDERNAME_MAXLEN];
285 : #define UMB_PHONENR_MAXLEN 22
286 : uint16_t pn[UMB_PHONENR_MAXLEN];
287 : #define UMB_SUBSCRIBERID_MAXLEN 15
288 : uint16_t sid[UMB_SUBSCRIBERID_MAXLEN];
289 : #define UMB_ICCID_MAXLEN 20
290 : uint16_t iccid[UMB_ICCID_MAXLEN];
291 : #define UMB_ROAMINGTEXT_MAXLEN 63
292 : uint16_t roamingtxt[UMB_ROAMINGTEXT_MAXLEN];
293 :
294 : #define UMB_DEVID_MAXLEN 18
295 : uint16_t devid[UMB_DEVID_MAXLEN];
296 : #define UMB_FWINFO_MAXLEN 30
297 : uint16_t fwinfo[UMB_FWINFO_MAXLEN];
298 : #define UMB_HWINFO_MAXLEN 30
299 : uint16_t hwinfo[UMB_HWINFO_MAXLEN];
300 :
301 : uint16_t apn[UMB_APN_MAXLEN];
302 : int apnlen;
303 :
304 : #define UMB_VALUE_UNKNOWN -999
305 : int rssi;
306 : #define UMB_BER_EXCELLENT 0
307 : #define UMB_BER_VERYGOOD 1
308 : #define UMB_BER_GOOD 2
309 : #define UMB_BER_OK 3
310 : #define UMB_BER_MEDIUM 4
311 : #define UMB_BER_BAD 5
312 : #define UMB_BER_VERYBAD 6
313 : #define UMB_BER_EXTREMELYBAD 7
314 : int ber;
315 :
316 : int hw_radio_on;
317 : int sw_radio_on;
318 :
319 : uint64_t uplink_speed;
320 : uint64_t downlink_speed;
321 :
322 : #define UMB_MAX_DNSSRV 2
323 : u_int32_t ipv4dns[UMB_MAX_DNSSRV];
324 : };
325 :
326 : #ifdef _KERNEL
327 : /*
328 : * UMB device
329 : */
330 : struct umb_softc {
331 : struct device sc_dev;
332 : struct ifnet sc_if;
333 : #define GET_IFP(sc) (&(sc)->sc_if)
334 : struct usbd_device *sc_udev;
335 :
336 : int sc_ver_maj;
337 : int sc_ver_min;
338 : int sc_ctrl_len;
339 : int sc_maxpktlen;
340 : int sc_maxsessions;
341 :
342 : int sc_maxdgram;
343 : int sc_align;
344 : int sc_ndp_div;
345 : int sc_ndp_remainder;
346 :
347 : #define UMBFLG_FCC_AUTH_REQUIRED 0x0001
348 : uint32_t sc_flags;
349 : int sc_cid;
350 :
351 : struct usb_task sc_umb_task;
352 : struct usb_task sc_get_response_task;
353 : int sc_nresp;
354 : struct timeout sc_statechg_timer;
355 :
356 : uint8_t sc_ctrl_ifaceno;
357 : struct usbd_pipe *sc_ctrl_pipe;
358 : struct usb_cdc_notification sc_intr_msg;
359 : struct usbd_interface *sc_data_iface;
360 :
361 : void *sc_resp_buf;
362 : void *sc_ctrl_msg;
363 :
364 : int sc_rx_ep;
365 : struct usbd_xfer *sc_rx_xfer;
366 : void *sc_rx_buf;
367 : int sc_rx_bufsz;
368 : struct usbd_pipe *sc_rx_pipe;
369 : unsigned sc_rx_nerr;
370 :
371 : int sc_tx_ep;
372 : struct usbd_xfer *sc_tx_xfer;
373 : void *sc_tx_buf;
374 : int sc_tx_bufsz;
375 : struct usbd_pipe *sc_tx_pipe;
376 : struct mbuf_list sc_tx_ml;
377 : uint32_t sc_tx_seq;
378 :
379 : uint32_t sc_tid;
380 :
381 : #define sc_state sc_info.state
382 : #define sc_roaming sc_info.enable_roaming
383 : struct umb_info sc_info;
384 : };
385 : #endif /* _KERNEL */
|