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