1223864Shselasky/* $FreeBSD$ */
2223864Shselasky
3223864Shselasky/*-
4223864Shselasky * Copyright (c) 2011 Anybots Inc
5223864Shselasky * written by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
6223864Shselasky *  - ucom part is based on u3g.c
7223864Shselasky *
8223864Shselasky * Redistribution and use in source and binary forms, with or without
9223864Shselasky * modification, are permitted provided that the following conditions
10223864Shselasky * are met:
11223864Shselasky * 1. Redistributions of source code must retain the above copyright
12223864Shselasky *    notice, this list of conditions and the following disclaimer.
13223864Shselasky * 2. Redistributions in binary form must reproduce the above copyright
14223864Shselasky *    notice, this list of conditions and the following disclaimer in the
15223864Shselasky *    documentation and/or other materials provided with the distribution.
16223864Shselasky *
17223864Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18223864Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19223864Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20223864Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21223864Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22223864Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23223864Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24223864Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25223864Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26223864Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27223864Shselasky * SUCH DAMAGE.
28223864Shselasky */
29223864Shselasky
30223864Shselasky#ifndef _IF_USEVAR_H_
31223864Shselasky#define	_IF_USEVAR_H_
32223864Shselasky
33223864Shselasky#define	USIE_DCD		0x0001
34223864Shselasky#define	USIE_DSR		0x0002
35223864Shselasky#define	USIE_DTR		0x0004
36223864Shselasky#define	USIE_RI			0x0008
37223864Shselasky#define	USIE_CTS		0x0100
38223864Shselasky#define	USIE_RTS		0x0200
39223864Shselasky
40223864Shselasky#define	USIE_HIP_FRM_CHR	0x7e
41223864Shselasky#define	USIE_HIP_ESC_CHR	0x7d
42223864Shselasky#define	USIE_HIP_IF		0
43223864Shselasky
44223864Shselasky#define	USIE_HIPCNS_MIN		16	/* HIP + CnS + 2 framing char */
45223864Shselasky#define	USIE_HIPCNS_MAX		261	/* HIP + max CnS 255 + 2 framing char */
46223864Shselasky
47223864Shselasky#define	USIE_CNFG_INDEX		0
48223864Shselasky#define	USIE_IFACE_INDEX	0
49223864Shselasky#define	USIE_IFACE_MAX		12
50223864Shselasky#define	USIE_BUFSIZE		2048
51223864Shselasky#define	USIE_MTU_MAX		1500
52223864Shselasky#define	USIE_RXSZ_MAX		4096
53223864Shselasky
54223864Shselasky/* USB control pipe request */
55223864Shselasky#define	USIE_POWER		0x00
56223864Shselasky#define	USIE_FW_ATTR		0x06
57223864Shselasky#define	USIE_NMEA		0x07
58223864Shselasky#define	USIE_LINK_STATE		0x22
59223864Shselasky
60223864Shselasky/* firmware attr flags */
61223864Shselasky#define	USIE_PM_AUTO		(1 << 1)
62223864Shselasky#define	USIE_FW_DHCP		(1 << 3)	/* DHCP capable */
63223864Shselasky
64223864Shselasky/* line state flags */
65223864Shselasky#define	USIE_LS_DTR		(1 << 0)
66223864Shselasky#define	USIE_LS_RTS		(1 << 1)
67223864Shselasky
68223864Shselasky/* Host Interface Porotocol Header */
69223864Shselaskystruct usie_hip {
70223864Shselasky	uint16_t len;
71223864Shselasky#define	USIE_HIP_LEN_MASK	0x3fff
72223864Shselasky#define	USIE_HIP_IP_LEN_MASK	0x07ff
73223864Shselasky
74223864Shselasky	uint8_t	id;
75223864Shselasky#define	USIE_HIP_PAD		(1 << 7)
76223864Shselasky#define	USIE_HIP_MASK		0x7f
77223864Shselasky#define	USIE_HIP_SYNC2M		0x20	/* host -> modem */
78223864Shselasky#define	USIE_HIP_DOWN		0x26
79223864Shselasky#define	USIE_HIP_CNS2M		0x2b	/* h -> m */
80223864Shselasky#define	USIE_HIP_CTX		0x3f
81223864Shselasky#define	USIE_HIP_SYNC2H		0x60	/* h <- m */
82223864Shselasky#define	USIE_HIP_RESTR		0x62
83223864Shselasky#define	USIE_HIP_RCGI		0x64
84223864Shselasky#define	USIE_HIP_CNS2H		0x6b	/* h <- m */
85223864Shselasky#define	USIE_HIP_UMTS		0x78
86223864Shselasky#define	USIE_HIP_IP		0x7f
87223864Shselasky
88223864Shselasky	uint8_t	param;
89223864Shselasky} __packed __aligned(4);
90223864Shselasky
91223864Shselasky/* Control and Status Header */
92223864Shselaskystruct usie_cns {
93223864Shselasky	uint16_t obj;			/* object type */
94223864Shselasky#define	USIE_CNS_OB_RSSI	0x1001	/* read RSSI */
95223864Shselasky#define	USIE_CNS_OB_HW_DISABLE	0x1011	/* disable h/w */
96223864Shselasky#define	USIE_CNS_OB_PW_SW	0x1071	/* power on/off */
97223864Shselasky#define	USIE_CNS_OB_PROF_WRITE	0x7003	/* write profile */
98223864Shselasky#define	USIE_CNS_OB_LINK_UPDATE	0x7004	/* dis/connect */
99223864Shselasky#define	USIE_CNS_OB_PDP_READ	0x7006	/* read out IP addr */
100223864Shselasky
101223864Shselasky	uint8_t	op;			/* operation type */
102223864Shselasky#define	USIE_CNS_OP_ERR		(1 << 7)/* | == error */
103223864Shselasky#define	USIE_CNS_OP_REQ		0x01	/* host -> modem */
104223864Shselasky#define	USIE_CNS_OP_RSP		0x02	/* h <- m */
105223864Shselasky#define	USIE_CNS_OP_SET		0x03	/* h -> m */
106223864Shselasky#define	USIE_CNS_OP_ACK		0x04	/* h <- m */
107223864Shselasky#define	USIE_CNS_OP_NOTIF_ON	0x05	/* h -> m */
108223864Shselasky#define	USIE_CNS_OP_RSP_ON	0x06	/* h <- m */
109223864Shselasky#define	USIE_CNS_OP_NOTIF	0x07	/* h <- m */
110223864Shselasky#define	USIE_CNS_OP_NOTIF_OFF	0x08	/* h -> m */
111223864Shselasky#define	USIE_CNS_OP_RSP_OFF	0x09	/* h <- m */
112223864Shselasky#define	USIE_CNS_OP_REQ_CHG	0x0a	/* h -> m */
113223864Shselasky#define	USIE_CNS_OP_RSP_CHG	0x0b	/* h <- m */
114223864Shselasky
115223864Shselasky	uint8_t	rsv0;			/* reserved, always '0' */
116223864Shselasky	uint32_t id;			/* caller ID */
117223864Shselasky/*
118223864Shselasky * .id is to identify calling functions
119223864Shselasky * h/w responses with the same .id used in request. Only '0' is reserved
120223864Shselasky * for notification (asynchronous message generated by h/w without any
121223864Shselasky * request). All other values are user defineable.
122223864Shselasky */
123223864Shselasky#define	USIE_CNS_ID_NOTIF	0x00000000	/* reserved */
124223864Shselasky#define	USIE_CNS_ID_INIT	0x00000001
125223864Shselasky#define	USIE_CNS_ID_STOP	0x00000002
126223864Shselasky#define	USIE_CNS_ID_DNS		0x00000003
127223864Shselasky#define	USIE_CNS_ID_RSSI	0x00000004
128223864Shselasky
129223864Shselasky	uint8_t	rsv1;			/* reserved, always '0' */
130223864Shselasky	uint8_t	len;			/* length of param */
131223864Shselasky} __packed;
132223864Shselasky
133223864Shselasky/*
134223864Shselasky * CnS param attached to struct usie_cns
135223864Shselasky * usie_cns.len is total size of this param
136223864Shselasky * max 255
137223864Shselasky */
138223864Shselasky#define	USIE_CNS_PM_UP		0x01
139223864Shselasky#define	USIE_CNS_PM_DOWN	0x00
140223864Shselasky
141223864Shselasky/* Link Sense Indication data structure */
142223864Shselaskystruct usie_lsi {
143223864Shselasky	uint8_t	proto;
144223864Shselasky#define	USIE_LSI_UMTS		0x01
145223864Shselasky
146223864Shselasky	uint8_t	pad0;
147223864Shselasky	uint16_t len;
148223864Shselasky	uint8_t	area;
149223864Shselasky#define	USIE_LSI_AREA_NO	0x00
150223864Shselasky#define	USIE_LSI_AREA_NODATA	0x01
151223864Shselasky
152223864Shselasky	uint8_t	pad1[41];
153223864Shselasky	uint8_t	state;
154223864Shselasky#define	USIE_LSI_STATE_IDLE	0x00
155223864Shselasky
156223864Shselasky	uint8_t	pad2[33];
157223864Shselasky	uint8_t	type;
158223864Shselasky#define	USIE_LSI_IP4		0x00
159223864Shselasky
160223864Shselasky	uint8_t	pdp_addr_len;		/* PDP addr */
161223864Shselasky	uint8_t	pdp_addr[16];
162223864Shselasky	uint8_t	pad3[23];
163223864Shselasky	uint8_t	dns1_addr_len;		/* DNS addr */
164223864Shselasky	uint8_t	dns1_addr[16];
165223864Shselasky	uint8_t	dns2_addr_len;
166223864Shselasky	uint8_t	dns2_addr[16];
167223864Shselasky	uint8_t	wins1_addr_len;		/* Wins addr */
168223864Shselasky	uint8_t	wins1_addr[16];
169223864Shselasky	uint8_t	wins2_addr_len;
170223864Shselasky	uint8_t	wins2_addr[16];
171223864Shselasky	uint8_t	pad4[4];
172223864Shselasky	uint8_t	gw_addr_len;		/* GW addr */
173223864Shselasky	uint8_t	gw_addr[16];
174223864Shselasky	uint8_t	rsv[8];
175223864Shselasky} __packed;
176223864Shselasky
177223864Shselaskystruct usie_net_info {
178223864Shselasky	uint8_t	addr_len;
179223864Shselasky	uint8_t	pdp_addr[16];
180223864Shselasky	uint8_t	dns1_addr[16];
181223864Shselasky	uint8_t	dns2_addr[16];
182223864Shselasky	uint8_t	gw_addr[16];
183223864Shselasky} __packed;
184223864Shselasky
185223864Shselasky/* Tx/Rx IP packet descriptor */
186223864Shselaskystruct usie_desc {
187223864Shselasky	struct usie_hip hip;
188223864Shselasky	uint16_t desc_type;
189223864Shselasky#define	USIE_TYPE_MASK	0x03ff
190223864Shselasky#define	USIE_IP_TX	0x0002
191223864Shselasky#define	USIE_IP_RX	0x0202
192223864Shselasky
193223864Shselasky	struct ether_header ethhdr;
194223864Shselasky} __packed;
195223864Shselasky
196223864Shselaskyenum {
197223864Shselasky	USIE_UC_STATUS,
198223864Shselasky	USIE_UC_RX,
199223864Shselasky	USIE_UC_TX,
200223864Shselasky	USIE_UC_N_XFER
201223864Shselasky};
202223864Shselasky
203223864Shselaskyenum {
204223864Shselasky	USIE_IF_STATUS,
205223864Shselasky	USIE_IF_RX,
206223864Shselasky	USIE_IF_TX,
207223864Shselasky	USIE_IF_N_XFER
208223864Shselasky};
209223864Shselasky
210223864Shselaskystruct usie_softc {
211223864Shselasky	struct ucom_super_softc sc_super_ucom;
212223864Shselasky
213223864Shselasky#define	USIE_UCOM_MAX	6
214223864Shselasky	struct ucom_softc sc_ucom[USIE_UCOM_MAX];
215223864Shselasky	uint8_t	sc_uc_ifnum[USIE_UCOM_MAX];
216223864Shselasky
217223864Shselasky	struct mtx sc_mtx;
218223864Shselasky
219223864Shselasky	struct task sc_if_status_task;
220223864Shselasky	struct task sc_if_sync_task;
221223864Shselasky	struct usb_callout sc_if_sync_ch;
222223864Shselasky
223223864Shselasky	struct usie_net_info sc_net;
224223864Shselasky
225223864Shselasky	struct usie_desc sc_txd;
226223864Shselasky
227223864Shselasky	struct usb_xfer *sc_uc_xfer[USIE_UCOM_MAX][USIE_UC_N_XFER];
228223864Shselasky	struct usb_xfer *sc_if_xfer[USIE_IF_N_XFER];
229223864Shselasky
230223864Shselasky	struct ifnet *sc_ifp;
231223864Shselasky	struct usb_device *sc_udev;
232223864Shselasky	device_t sc_dev;
233223864Shselasky
234223864Shselasky	struct mbuf *sc_rxm;
235223864Shselasky
236223864Shselasky	uint16_t sc_if_ifnum;
237223864Shselasky
238223864Shselasky	int16_t	sc_rssi;
239223864Shselasky
240223864Shselasky	uint8_t	sc_msr;
241223864Shselasky	uint8_t	sc_lsr;
242223864Shselasky	uint8_t	sc_nucom;
243223864Shselasky
244223864Shselasky	uint8_t	sc_resp_temp[USIE_BUFSIZE] __aligned(4);
245223864Shselasky	uint8_t	sc_status_temp[USIE_BUFSIZE] __aligned(4);
246223864Shselasky};
247223864Shselasky
248223864Shselasky/* Some code assumptions */
249223864Shselasky
250223864Shselaskyextern uint8_t usie_assert[((sizeof(struct usie_hip) +
251223864Shselasky    sizeof(struct usie_lsi) + 1) <= USIE_BUFSIZE) ? 1 : -1];
252223864Shselasky
253223864Shselaskyextern uint8_t ucdc_assert[(sizeof(struct usb_cdc_notification)
254223864Shselasky     >= 16) ? 1 : -1];
255223864Shselasky
256223864Shselasky#endif					/* _IF_USEVAR_H_ */
257