Loading...
1/*
2 * u_ether.h -- interface to USB gadget "ethernet link" utilities
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __U_ETHER_H
24#define __U_ETHER_H
25
26#include <linux/err.h>
27#include <linux/if_ether.h>
28#include <linux/usb/composite.h>
29#include <linux/usb/cdc.h>
30
31#include "gadget_chips.h"
32
33
34/*
35 * This represents the USB side of an "ethernet" link, managed by a USB
36 * function which provides control and (maybe) framing. Two functions
37 * in different configurations could share the same ethernet link/netdev,
38 * using different host interaction models.
39 *
40 * There is a current limitation that only one instance of this link may
41 * be present in any given configuration. When that's a problem, network
42 * layer facilities can be used to package multiple logical links on this
43 * single "physical" one.
44 */
45struct gether {
46 struct usb_function func;
47
48 /* updated by gether_{connect,disconnect} */
49 struct eth_dev *ioport;
50
51 /* endpoints handle full and/or high speeds */
52 struct usb_ep *in_ep;
53 struct usb_ep *out_ep;
54
55 bool is_zlp_ok;
56
57 u16 cdc_filter;
58
59 /* hooks for added framing, as needed for RNDIS and EEM. */
60 u32 header_len;
61 /* NCM requires fixed size bundles */
62 bool is_fixed;
63 u32 fixed_out_len;
64 u32 fixed_in_len;
65 struct sk_buff *(*wrap)(struct gether *port,
66 struct sk_buff *skb);
67 int (*unwrap)(struct gether *port,
68 struct sk_buff *skb,
69 struct sk_buff_head *list);
70
71 /* called on network open/close */
72 void (*open)(struct gether *);
73 void (*close)(struct gether *);
74};
75
76#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
77 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
78 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
79 |USB_CDC_PACKET_TYPE_DIRECTED)
80
81
82/* netdev setup/teardown as directed by the gadget driver */
83int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
84void gether_cleanup(void);
85
86/* connect/disconnect is handled by individual functions */
87struct net_device *gether_connect(struct gether *);
88void gether_disconnect(struct gether *);
89
90/* Some controllers can't support CDC Ethernet (ECM) ... */
91static inline bool can_support_ecm(struct usb_gadget *gadget)
92{
93 if (!gadget_supports_altsettings(gadget))
94 return false;
95
96 /* Everything else is *presumably* fine ... but this is a bit
97 * chancy, so be **CERTAIN** there are no hardware issues with
98 * your controller. Add it above if it can't handle CDC.
99 */
100 return true;
101}
102
103/* each configuration may bind one instance of an ethernet link */
104int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
105int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
106int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
107int eem_bind_config(struct usb_configuration *c);
108
109#ifdef USB_ETH_RNDIS
110
111int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
112
113#else
114
115static inline int
116rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
117{
118 return 0;
119}
120
121#endif
122
123#endif /* __U_ETHER_H */
1/*
2 * u_ether.h -- interface to USB gadget "ethernet link" utilities
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef __U_ETHER_H
15#define __U_ETHER_H
16
17#include <linux/err.h>
18#include <linux/if_ether.h>
19#include <linux/usb/composite.h>
20#include <linux/usb/cdc.h>
21
22#include "gadget_chips.h"
23
24
25/*
26 * This represents the USB side of an "ethernet" link, managed by a USB
27 * function which provides control and (maybe) framing. Two functions
28 * in different configurations could share the same ethernet link/netdev,
29 * using different host interaction models.
30 *
31 * There is a current limitation that only one instance of this link may
32 * be present in any given configuration. When that's a problem, network
33 * layer facilities can be used to package multiple logical links on this
34 * single "physical" one.
35 */
36struct gether {
37 struct usb_function func;
38
39 /* updated by gether_{connect,disconnect} */
40 struct eth_dev *ioport;
41
42 /* endpoints handle full and/or high speeds */
43 struct usb_ep *in_ep;
44 struct usb_ep *out_ep;
45
46 bool is_zlp_ok;
47
48 u16 cdc_filter;
49
50 /* hooks for added framing, as needed for RNDIS and EEM. */
51 u32 header_len;
52 /* NCM requires fixed size bundles */
53 bool is_fixed;
54 u32 fixed_out_len;
55 u32 fixed_in_len;
56 struct sk_buff *(*wrap)(struct gether *port,
57 struct sk_buff *skb);
58 int (*unwrap)(struct gether *port,
59 struct sk_buff *skb,
60 struct sk_buff_head *list);
61
62 /* called on network open/close */
63 void (*open)(struct gether *);
64 void (*close)(struct gether *);
65};
66
67#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
68 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
69 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
70 |USB_CDC_PACKET_TYPE_DIRECTED)
71
72/* variant of gether_setup that allows customizing network device name */
73int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
74 const char *netname);
75
76/* netdev setup/teardown as directed by the gadget driver */
77/* gether_setup - initialize one ethernet-over-usb link
78 * @g: gadget to associated with these links
79 * @ethaddr: NULL, or a buffer in which the ethernet address of the
80 * host side of the link is recorded
81 * Context: may sleep
82 *
83 * This sets up the single network link that may be exported by a
84 * gadget driver using this framework. The link layer addresses are
85 * set up using module parameters.
86 *
87 * Returns negative errno, or zero on success
88 */
89static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
90{
91 return gether_setup_name(g, ethaddr, "usb");
92}
93
94void gether_cleanup(void);
95
96/* connect/disconnect is handled by individual functions */
97struct net_device *gether_connect(struct gether *);
98void gether_disconnect(struct gether *);
99
100/* Some controllers can't support CDC Ethernet (ECM) ... */
101static inline bool can_support_ecm(struct usb_gadget *gadget)
102{
103 if (!gadget_supports_altsettings(gadget))
104 return false;
105
106 /* Everything else is *presumably* fine ... but this is a bit
107 * chancy, so be **CERTAIN** there are no hardware issues with
108 * your controller. Add it above if it can't handle CDC.
109 */
110 return true;
111}
112
113/* each configuration may bind one instance of an ethernet link */
114int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
115int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
116int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
117int eem_bind_config(struct usb_configuration *c);
118
119#ifdef USB_ETH_RNDIS
120
121int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
122 u32 vendorID, const char *manufacturer);
123
124#else
125
126static inline int
127rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
128 u32 vendorID, const char *manufacturer)
129{
130 return 0;
131}
132
133#endif
134
135/**
136 * rndis_bind_config - add RNDIS network link to a configuration
137 * @c: the configuration to support the network link
138 * @ethaddr: a buffer in which the ethernet address of the host side
139 * side of the link was recorded
140 * Context: single threaded during gadget setup
141 *
142 * Returns zero on success, else negative errno.
143 *
144 * Caller must have called @gether_setup(). Caller is also responsible
145 * for calling @gether_cleanup() before module unload.
146 */
147static inline int rndis_bind_config(struct usb_configuration *c,
148 u8 ethaddr[ETH_ALEN])
149{
150 return rndis_bind_config_vendor(c, ethaddr, 0, NULL);
151}
152
153
154#endif /* __U_ETHER_H */