xref: /freebsd/sys/dev/usb/net/if_usievar.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1 
2 /*-
3  * Copyright (c) 2011 Anybots Inc
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * written by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
7  *  - ucom part is based on u3g.c
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef _IF_USEVAR_H_
32 #define	_IF_USEVAR_H_
33 
34 #define	USIE_DCD		0x0001
35 #define	USIE_DSR		0x0002
36 #define	USIE_DTR		0x0004
37 #define	USIE_RI			0x0008
38 #define	USIE_CTS		0x0100
39 #define	USIE_RTS		0x0200
40 
41 #define	USIE_HIP_FRM_CHR	0x7e
42 #define	USIE_HIP_ESC_CHR	0x7d
43 #define	USIE_HIP_IF		0
44 
45 #define	USIE_HIPCNS_MIN		16	/* HIP + CnS + 2 framing char */
46 #define	USIE_HIPCNS_MAX		261	/* HIP + max CnS 255 + 2 framing char */
47 
48 #define	USIE_CNFG_INDEX		0
49 #define	USIE_IFACE_INDEX	0
50 #define	USIE_IFACE_MAX		12
51 #define	USIE_BUFSIZE		2048
52 #define	USIE_MTU_MAX		1500
53 #define	USIE_RXSZ_MAX		4096
54 
55 /* USB control pipe request */
56 #define	USIE_POWER		0x00
57 #define	USIE_FW_ATTR		0x06
58 #define	USIE_NMEA		0x07
59 #define	USIE_LINK_STATE		0x22
60 
61 /* firmware attr flags */
62 #define	USIE_PM_AUTO		(1 << 1)
63 #define	USIE_FW_DHCP		(1 << 3)	/* DHCP capable */
64 
65 /* line state flags */
66 #define	USIE_LS_DTR		(1 << 0)
67 #define	USIE_LS_RTS		(1 << 1)
68 
69 /* Host Interface Porotocol Header */
70 struct usie_hip {
71 	uint16_t len;
72 #define	USIE_HIP_LEN_MASK	0x3fff
73 #define	USIE_HIP_IP_LEN_MASK	0x07ff
74 
75 	uint8_t	id;
76 #define	USIE_HIP_PAD		(1 << 7)
77 #define	USIE_HIP_MASK		0x7f
78 #define	USIE_HIP_SYNC2M		0x20	/* host -> modem */
79 #define	USIE_HIP_DOWN		0x26
80 #define	USIE_HIP_CNS2M		0x2b	/* h -> m */
81 #define	USIE_HIP_CTX		0x3f
82 #define	USIE_HIP_SYNC2H		0x60	/* h <- m */
83 #define	USIE_HIP_RESTR		0x62
84 #define	USIE_HIP_RCGI		0x64
85 #define	USIE_HIP_CNS2H		0x6b	/* h <- m */
86 #define	USIE_HIP_UMTS		0x78
87 #define	USIE_HIP_IP		0x7f
88 
89 	uint8_t	param;
90 } __packed __aligned(4);
91 
92 /* Control and Status Header */
93 struct usie_cns {
94 	uint16_t obj;			/* object type */
95 #define	USIE_CNS_OB_RSSI	0x1001	/* read RSSI */
96 #define	USIE_CNS_OB_HW_DISABLE	0x1011	/* disable h/w */
97 #define	USIE_CNS_OB_PW_SW	0x1071	/* power on/off */
98 #define	USIE_CNS_OB_PROF_WRITE	0x7003	/* write profile */
99 #define	USIE_CNS_OB_LINK_UPDATE	0x7004	/* dis/connect */
100 #define	USIE_CNS_OB_PDP_READ	0x7006	/* read out IP addr */
101 
102 	uint8_t	op;			/* operation type */
103 #define	USIE_CNS_OP_ERR		(1 << 7)/* | == error */
104 #define	USIE_CNS_OP_REQ		0x01	/* host -> modem */
105 #define	USIE_CNS_OP_RSP		0x02	/* h <- m */
106 #define	USIE_CNS_OP_SET		0x03	/* h -> m */
107 #define	USIE_CNS_OP_ACK		0x04	/* h <- m */
108 #define	USIE_CNS_OP_NOTIF_ON	0x05	/* h -> m */
109 #define	USIE_CNS_OP_RSP_ON	0x06	/* h <- m */
110 #define	USIE_CNS_OP_NOTIF	0x07	/* h <- m */
111 #define	USIE_CNS_OP_NOTIF_OFF	0x08	/* h -> m */
112 #define	USIE_CNS_OP_RSP_OFF	0x09	/* h <- m */
113 #define	USIE_CNS_OP_REQ_CHG	0x0a	/* h -> m */
114 #define	USIE_CNS_OP_RSP_CHG	0x0b	/* h <- m */
115 
116 	uint8_t	rsv0;			/* reserved, always '0' */
117 	uint32_t id;			/* caller ID */
118 /*
119  * .id is to identify calling functions
120  * h/w responses with the same .id used in request. Only '0' is reserved
121  * for notification (asynchronous message generated by h/w without any
122  * request). All other values are user defineable.
123  */
124 #define	USIE_CNS_ID_NOTIF	0x00000000	/* reserved */
125 #define	USIE_CNS_ID_INIT	0x00000001
126 #define	USIE_CNS_ID_STOP	0x00000002
127 #define	USIE_CNS_ID_DNS		0x00000003
128 #define	USIE_CNS_ID_RSSI	0x00000004
129 
130 	uint8_t	rsv1;			/* reserved, always '0' */
131 	uint8_t	len;			/* length of param */
132 } __packed;
133 
134 /*
135  * CnS param attached to struct usie_cns
136  * usie_cns.len is total size of this param
137  * max 255
138  */
139 #define	USIE_CNS_PM_UP		0x01
140 #define	USIE_CNS_PM_DOWN	0x00
141 
142 /* Link Sense Indication data structure */
143 struct usie_lsi {
144 	uint8_t	proto;
145 #define	USIE_LSI_UMTS		0x01
146 
147 	uint8_t	pad0;
148 	uint16_t len;
149 	uint8_t	area;
150 #define	USIE_LSI_AREA_NO	0x00
151 #define	USIE_LSI_AREA_NODATA	0x01
152 
153 	uint8_t	pad1[41];
154 	uint8_t	state;
155 #define	USIE_LSI_STATE_IDLE	0x00
156 
157 	uint8_t	pad2[33];
158 	uint8_t	type;
159 #define	USIE_LSI_IP4		0x00
160 
161 	uint8_t	pdp_addr_len;		/* PDP addr */
162 	uint8_t	pdp_addr[16];
163 	uint8_t	pad3[23];
164 	uint8_t	dns1_addr_len;		/* DNS addr */
165 	uint8_t	dns1_addr[16];
166 	uint8_t	dns2_addr_len;
167 	uint8_t	dns2_addr[16];
168 	uint8_t	wins1_addr_len;		/* Wins addr */
169 	uint8_t	wins1_addr[16];
170 	uint8_t	wins2_addr_len;
171 	uint8_t	wins2_addr[16];
172 	uint8_t	pad4[4];
173 	uint8_t	gw_addr_len;		/* GW addr */
174 	uint8_t	gw_addr[16];
175 	uint8_t	rsv[8];
176 } __packed;
177 
178 struct usie_net_info {
179 	uint8_t	addr_len;
180 	uint8_t	pdp_addr[16];
181 	uint8_t	dns1_addr[16];
182 	uint8_t	dns2_addr[16];
183 	uint8_t	gw_addr[16];
184 } __packed;
185 
186 /* Tx/Rx IP packet descriptor */
187 struct usie_desc {
188 	struct usie_hip hip;
189 	uint16_t desc_type;
190 #define	USIE_TYPE_MASK	0x03ff
191 #define	USIE_IP_TX	0x0002
192 #define	USIE_IP_RX	0x0202
193 
194 	struct ether_header ethhdr;
195 } __packed;
196 
197 enum {
198 	USIE_UC_STATUS,
199 	USIE_UC_RX,
200 	USIE_UC_TX,
201 	USIE_UC_N_XFER
202 };
203 
204 enum {
205 	USIE_IF_STATUS,
206 	USIE_IF_RX,
207 	USIE_IF_TX,
208 	USIE_IF_N_XFER
209 };
210 
211 struct usie_softc {
212 	struct ucom_super_softc sc_super_ucom;
213 
214 #define	USIE_UCOM_MAX	6
215 	struct ucom_softc sc_ucom[USIE_UCOM_MAX];
216 	uint8_t	sc_uc_ifnum[USIE_UCOM_MAX];
217 
218 	struct mtx sc_mtx;
219 
220 	struct task sc_if_status_task;
221 	struct task sc_if_sync_task;
222 	struct usb_callout sc_if_sync_ch;
223 
224 	struct usie_net_info sc_net;
225 
226 	struct usie_desc sc_txd;
227 
228 	struct usb_xfer *sc_uc_xfer[USIE_UCOM_MAX][USIE_UC_N_XFER];
229 	struct usb_xfer *sc_if_xfer[USIE_IF_N_XFER];
230 
231 	if_t sc_ifp;
232 	struct usb_device *sc_udev;
233 	device_t sc_dev;
234 
235 	struct mbuf *sc_rxm;
236 
237 	uint16_t sc_if_ifnum;
238 
239 	int16_t	sc_rssi;
240 
241 	uint8_t	sc_msr;
242 	uint8_t	sc_lsr;
243 	uint8_t	sc_nucom;
244 
245 	uint8_t	sc_resp_temp[USIE_BUFSIZE] __aligned(4);
246 	uint8_t	sc_status_temp[USIE_BUFSIZE] __aligned(4);
247 };
248 
249 /* Some code assumptions */
250 
251 extern uint8_t usie_assert[((sizeof(struct usie_hip) +
252     sizeof(struct usie_lsi) + 1) <= USIE_BUFSIZE) ? 1 : -1];
253 
254 extern uint8_t ucdc_assert[(sizeof(struct usb_cdc_notification)
255      >= 16) ? 1 : -1];
256 
257 #endif					/* _IF_USEVAR_H_ */
258