blob: 8aa2be5329bcff2a3619c4aa0044c944afa5566f [file] [log] [blame]
Felipe Balbi30867752008-08-18 17:39:30 -07001/*
2 * f_obex.c -- USB CDC OBEX function driver
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
6 *
7 * Based on f_acm.c by Al Borchers and David Brownell.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
Felipe Balbi30867752008-08-18 17:39:30 -070013 */
14
15/* #define VERBOSE_DEBUG */
16
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Felipe Balbi30867752008-08-18 17:39:30 -070018#include <linux/kernel.h>
Felipe Balbi30867752008-08-18 17:39:30 -070019#include <linux/device.h>
Paul Gortmaker6eb0de82011-07-03 16:09:31 -040020#include <linux/module.h>
Felipe Balbi30867752008-08-18 17:39:30 -070021
22#include "u_serial.h"
23#include "gadget_chips.h"
24
25
26/*
27 * This CDC OBEX function support just packages a TTY-ish byte stream.
28 * A user mode server will put it into "raw" mode and handle all the
29 * relevant protocol details ... this is just a kernel passthrough.
David Brownell21214272008-08-18 17:45:25 -070030 * When possible, we prevent gadget enumeration until that server is
31 * ready to handle the commands.
Felipe Balbi30867752008-08-18 17:39:30 -070032 */
33
Felipe Balbi30867752008-08-18 17:39:30 -070034struct f_obex {
35 struct gserial port;
36 u8 ctrl_id;
37 u8 data_id;
38 u8 port_num;
David Brownell21214272008-08-18 17:45:25 -070039 u8 can_activate;
Felipe Balbi30867752008-08-18 17:39:30 -070040};
41
42static inline struct f_obex *func_to_obex(struct usb_function *f)
43{
44 return container_of(f, struct f_obex, port.func);
45}
46
David Brownell21214272008-08-18 17:45:25 -070047static inline struct f_obex *port_to_obex(struct gserial *p)
48{
49 return container_of(p, struct f_obex, port);
50}
51
Felipe Balbi30867752008-08-18 17:39:30 -070052/*-------------------------------------------------------------------------*/
53
54#define OBEX_CTRL_IDX 0
55#define OBEX_DATA_IDX 1
56
57static struct usb_string obex_string_defs[] = {
58 [OBEX_CTRL_IDX].s = "CDC Object Exchange (OBEX)",
59 [OBEX_DATA_IDX].s = "CDC OBEX Data",
60 { }, /* end of list */
61};
62
63static struct usb_gadget_strings obex_string_table = {
64 .language = 0x0409, /* en-US */
65 .strings = obex_string_defs,
66};
67
68static struct usb_gadget_strings *obex_strings[] = {
69 &obex_string_table,
70 NULL,
71};
72
73/*-------------------------------------------------------------------------*/
74
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +010075static struct usb_interface_descriptor obex_control_intf = {
Felipe Balbi30867752008-08-18 17:39:30 -070076 .bLength = sizeof(obex_control_intf),
77 .bDescriptorType = USB_DT_INTERFACE,
78 .bInterfaceNumber = 0,
79
80 .bAlternateSetting = 0,
81 .bNumEndpoints = 0,
82 .bInterfaceClass = USB_CLASS_COMM,
83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX,
84};
85
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +010086static struct usb_interface_descriptor obex_data_nop_intf = {
Felipe Balbi30867752008-08-18 17:39:30 -070087 .bLength = sizeof(obex_data_nop_intf),
88 .bDescriptorType = USB_DT_INTERFACE,
89 .bInterfaceNumber = 1,
90
91 .bAlternateSetting = 0,
92 .bNumEndpoints = 0,
93 .bInterfaceClass = USB_CLASS_CDC_DATA,
94};
95
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +010096static struct usb_interface_descriptor obex_data_intf = {
Felipe Balbi30867752008-08-18 17:39:30 -070097 .bLength = sizeof(obex_data_intf),
98 .bDescriptorType = USB_DT_INTERFACE,
99 .bInterfaceNumber = 2,
100
101 .bAlternateSetting = 1,
102 .bNumEndpoints = 2,
103 .bInterfaceClass = USB_CLASS_CDC_DATA,
104};
105
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100106static struct usb_cdc_header_desc obex_cdc_header_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700107 .bLength = sizeof(obex_cdc_header_desc),
108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
Harvey Harrison551509d2009-02-11 14:11:36 -0800110 .bcdCDC = cpu_to_le16(0x0120),
Felipe Balbi30867752008-08-18 17:39:30 -0700111};
112
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100113static struct usb_cdc_union_desc obex_cdc_union_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700114 .bLength = sizeof(obex_cdc_union_desc),
115 .bDescriptorType = USB_DT_CS_INTERFACE,
116 .bDescriptorSubType = USB_CDC_UNION_TYPE,
117 .bMasterInterface0 = 1,
118 .bSlaveInterface0 = 2,
119};
120
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100121static struct usb_cdc_obex_desc obex_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700122 .bLength = sizeof(obex_desc),
123 .bDescriptorType = USB_DT_CS_INTERFACE,
124 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
Harvey Harrison551509d2009-02-11 14:11:36 -0800125 .bcdVersion = cpu_to_le16(0x0100),
Felipe Balbi30867752008-08-18 17:39:30 -0700126};
127
128/* High-Speed Support */
129
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100130static struct usb_endpoint_descriptor obex_hs_ep_out_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700131 .bLength = USB_DT_ENDPOINT_SIZE,
132 .bDescriptorType = USB_DT_ENDPOINT,
133
134 .bEndpointAddress = USB_DIR_OUT,
135 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800136 .wMaxPacketSize = cpu_to_le16(512),
Felipe Balbi30867752008-08-18 17:39:30 -0700137};
138
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100139static struct usb_endpoint_descriptor obex_hs_ep_in_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT,
142
143 .bEndpointAddress = USB_DIR_IN,
144 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800145 .wMaxPacketSize = cpu_to_le16(512),
Felipe Balbi30867752008-08-18 17:39:30 -0700146};
147
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100148static struct usb_descriptor_header *hs_function[] = {
Felipe Balbi30867752008-08-18 17:39:30 -0700149 (struct usb_descriptor_header *) &obex_control_intf,
150 (struct usb_descriptor_header *) &obex_cdc_header_desc,
151 (struct usb_descriptor_header *) &obex_desc,
152 (struct usb_descriptor_header *) &obex_cdc_union_desc,
153
154 (struct usb_descriptor_header *) &obex_data_nop_intf,
155 (struct usb_descriptor_header *) &obex_data_intf,
156 (struct usb_descriptor_header *) &obex_hs_ep_in_desc,
157 (struct usb_descriptor_header *) &obex_hs_ep_out_desc,
158 NULL,
159};
160
161/* Full-Speed Support */
162
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100163static struct usb_endpoint_descriptor obex_fs_ep_in_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT,
166
167 .bEndpointAddress = USB_DIR_IN,
168 .bmAttributes = USB_ENDPOINT_XFER_BULK,
169};
170
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100171static struct usb_endpoint_descriptor obex_fs_ep_out_desc = {
Felipe Balbi30867752008-08-18 17:39:30 -0700172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT,
174
175 .bEndpointAddress = USB_DIR_OUT,
176 .bmAttributes = USB_ENDPOINT_XFER_BULK,
177};
178
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100179static struct usb_descriptor_header *fs_function[] = {
Felipe Balbi30867752008-08-18 17:39:30 -0700180 (struct usb_descriptor_header *) &obex_control_intf,
181 (struct usb_descriptor_header *) &obex_cdc_header_desc,
182 (struct usb_descriptor_header *) &obex_desc,
183 (struct usb_descriptor_header *) &obex_cdc_union_desc,
184
185 (struct usb_descriptor_header *) &obex_data_nop_intf,
186 (struct usb_descriptor_header *) &obex_data_intf,
187 (struct usb_descriptor_header *) &obex_fs_ep_in_desc,
188 (struct usb_descriptor_header *) &obex_fs_ep_out_desc,
189 NULL,
190};
191
192/*-------------------------------------------------------------------------*/
193
194static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
195{
196 struct f_obex *obex = func_to_obex(f);
197 struct usb_composite_dev *cdev = f->config->cdev;
198
199 if (intf == obex->ctrl_id) {
200 if (alt != 0)
201 goto fail;
202 /* NOP */
203 DBG(cdev, "reset obex ttyGS%d control\n", obex->port_num);
204
205 } else if (intf == obex->data_id) {
206 if (alt > 1)
207 goto fail;
208
209 if (obex->port.in->driver_data) {
210 DBG(cdev, "reset obex ttyGS%d\n", obex->port_num);
211 gserial_disconnect(&obex->port);
212 }
213
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300214 if (!obex->port.in->desc || !obex->port.out->desc) {
Felipe Balbi30867752008-08-18 17:39:30 -0700215 DBG(cdev, "init obex ttyGS%d\n", obex->port_num);
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300216 if (config_ep_by_speed(cdev->gadget, f,
217 obex->port.in) ||
218 config_ep_by_speed(cdev->gadget, f,
219 obex->port.out)) {
220 obex->port.out->desc = NULL;
221 obex->port.in->desc = NULL;
222 goto fail;
223 }
Felipe Balbi30867752008-08-18 17:39:30 -0700224 }
225
226 if (alt == 1) {
227 DBG(cdev, "activate obex ttyGS%d\n", obex->port_num);
228 gserial_connect(&obex->port, obex->port_num);
229 }
230
231 } else
232 goto fail;
233
234 return 0;
235
236fail:
237 return -EINVAL;
238}
239
240static int obex_get_alt(struct usb_function *f, unsigned intf)
241{
242 struct f_obex *obex = func_to_obex(f);
243
244 if (intf == obex->ctrl_id)
245 return 0;
246
247 return obex->port.in->driver_data ? 1 : 0;
248}
249
250static void obex_disable(struct usb_function *f)
251{
252 struct f_obex *obex = func_to_obex(f);
253 struct usb_composite_dev *cdev = f->config->cdev;
254
255 DBG(cdev, "obex ttyGS%d disable\n", obex->port_num);
256 gserial_disconnect(&obex->port);
257}
258
259/*-------------------------------------------------------------------------*/
260
David Brownell21214272008-08-18 17:45:25 -0700261static void obex_connect(struct gserial *g)
262{
263 struct f_obex *obex = port_to_obex(g);
264 struct usb_composite_dev *cdev = g->func.config->cdev;
265 int status;
266
267 if (!obex->can_activate)
268 return;
269
270 status = usb_function_activate(&g->func);
271 if (status)
272 DBG(cdev, "obex ttyGS%d function activate --> %d\n",
273 obex->port_num, status);
274}
275
276static void obex_disconnect(struct gserial *g)
277{
278 struct f_obex *obex = port_to_obex(g);
279 struct usb_composite_dev *cdev = g->func.config->cdev;
280 int status;
281
282 if (!obex->can_activate)
283 return;
284
285 status = usb_function_deactivate(&g->func);
286 if (status)
287 DBG(cdev, "obex ttyGS%d function deactivate --> %d\n",
288 obex->port_num, status);
289}
290
291/*-------------------------------------------------------------------------*/
292
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100293/* Some controllers can't support CDC OBEX ... */
294static inline bool can_support_obex(struct usb_configuration *c)
295{
296 /* Since the first interface is a NOP, we can ignore the
297 * issue of multi-interface support on most controllers.
298 *
299 * Altsettings are mandatory, however...
300 */
301 if (!gadget_supports_altsettings(c->cdev->gadget))
302 return false;
303
304 /* everything else is *probably* fine ... */
305 return true;
306}
307
308static int obex_bind(struct usb_configuration *c, struct usb_function *f)
Felipe Balbi30867752008-08-18 17:39:30 -0700309{
310 struct usb_composite_dev *cdev = c->cdev;
311 struct f_obex *obex = func_to_obex(f);
312 int status;
313 struct usb_ep *ep;
314
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100315 if (!can_support_obex(c))
316 return -EINVAL;
317
318 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
319 status = usb_string_ids_tab(c->cdev, obex_string_defs);
320 if (status < 0)
321 return status;
322 obex_control_intf.iInterface =
323 obex_string_defs[OBEX_CTRL_IDX].id;
324
325 status = obex_string_defs[OBEX_DATA_IDX].id;
326 obex_data_nop_intf.iInterface = status;
327 obex_data_intf.iInterface = status;
328 }
329
Felipe Balbi30867752008-08-18 17:39:30 -0700330 /* allocate instance-specific interface IDs, and patch descriptors */
331
332 status = usb_interface_id(c, f);
333 if (status < 0)
334 goto fail;
335 obex->ctrl_id = status;
336
337 obex_control_intf.bInterfaceNumber = status;
338 obex_cdc_union_desc.bMasterInterface0 = status;
339
340 status = usb_interface_id(c, f);
341 if (status < 0)
342 goto fail;
343 obex->data_id = status;
344
345 obex_data_nop_intf.bInterfaceNumber = status;
346 obex_data_intf.bInterfaceNumber = status;
347 obex_cdc_union_desc.bSlaveInterface0 = status;
348
349 /* allocate instance-specific endpoints */
350
Wei Yongjun6ee3e8e2013-04-06 12:39:49 +0800351 status = -ENODEV;
Felipe Balbi30867752008-08-18 17:39:30 -0700352 ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_in_desc);
353 if (!ep)
354 goto fail;
355 obex->port.in = ep;
356 ep->driver_data = cdev; /* claim */
357
358 ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_out_desc);
359 if (!ep)
360 goto fail;
361 obex->port.out = ep;
362 ep->driver_data = cdev; /* claim */
363
Felipe Balbi30867752008-08-18 17:39:30 -0700364 /* support all relevant hardware speeds... we expect that when
365 * hardware is dual speed, all bulk-capable endpoints work at
366 * both speeds
367 */
Felipe Balbi30867752008-08-18 17:39:30 -0700368
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200369 obex_hs_ep_in_desc.bEndpointAddress =
370 obex_fs_ep_in_desc.bEndpointAddress;
371 obex_hs_ep_out_desc.bEndpointAddress =
372 obex_fs_ep_out_desc.bEndpointAddress;
Felipe Balbi30867752008-08-18 17:39:30 -0700373
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200374 status = usb_assign_descriptors(f, fs_function, hs_function, NULL);
375 if (status)
376 goto fail;
Felipe Balbi30867752008-08-18 17:39:30 -0700377
David Brownell21214272008-08-18 17:45:25 -0700378 /* Avoid letting this gadget enumerate until the userspace
379 * OBEX server is active.
380 */
381 status = usb_function_deactivate(f);
382 if (status < 0)
383 WARNING(cdev, "obex ttyGS%d: can't prevent enumeration, %d\n",
384 obex->port_num, status);
385 else
386 obex->can_activate = true;
387
388
Felipe Balbi30867752008-08-18 17:39:30 -0700389 DBG(cdev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n",
390 obex->port_num,
391 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
392 obex->port.in->name, obex->port.out->name);
393
394 return 0;
395
396fail:
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200397 usb_free_all_descriptors(f);
Felipe Balbi30867752008-08-18 17:39:30 -0700398 /* we might as well release our claims on endpoints */
399 if (obex->port.out)
400 obex->port.out->driver_data = NULL;
401 if (obex->port.in)
402 obex->port.in->driver_data = NULL;
403
404 ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
405
406 return status;
407}
408
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100409#ifdef USBF_OBEX_INCLUDED
410
Felipe Balbi30867752008-08-18 17:39:30 -0700411static void
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100412obex_old_unbind(struct usb_configuration *c, struct usb_function *f)
Felipe Balbi30867752008-08-18 17:39:30 -0700413{
Sebastian Andrzej Siewior1616e992012-10-22 22:15:10 +0200414 obex_string_defs[OBEX_CTRL_IDX].id = 0;
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200415 usb_free_all_descriptors(f);
Felipe Balbi30867752008-08-18 17:39:30 -0700416 kfree(func_to_obex(f));
417}
418
Felipe Balbi30867752008-08-18 17:39:30 -0700419/**
420 * obex_bind_config - add a CDC OBEX function to a configuration
421 * @c: the configuration to support the CDC OBEX instance
422 * @port_num: /dev/ttyGS* port this interface will use
423 * Context: single threaded during gadget setup
424 *
425 * Returns zero on success, else negative errno.
Felipe Balbi30867752008-08-18 17:39:30 -0700426 */
427int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
428{
429 struct f_obex *obex;
430 int status;
431
Felipe Balbi30867752008-08-18 17:39:30 -0700432 /* allocate and initialize one new instance */
433 obex = kzalloc(sizeof *obex, GFP_KERNEL);
434 if (!obex)
435 return -ENOMEM;
436
437 obex->port_num = port_num;
438
David Brownell21214272008-08-18 17:45:25 -0700439 obex->port.connect = obex_connect;
440 obex->port.disconnect = obex_disconnect;
441
Felipe Balbi30867752008-08-18 17:39:30 -0700442 obex->port.func.name = "obex";
443 obex->port.func.strings = obex_strings;
444 /* descriptors are per-instance copies */
445 obex->port.func.bind = obex_bind;
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100446 obex->port.func.unbind = obex_old_unbind;
Felipe Balbi30867752008-08-18 17:39:30 -0700447 obex->port.func.set_alt = obex_set_alt;
448 obex->port.func.get_alt = obex_get_alt;
449 obex->port.func.disable = obex_disable;
450
451 status = usb_add_function(c, &obex->port.func);
452 if (status)
453 kfree(obex);
454
455 return status;
456}
457
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100458#else
459
Andrzej Pietrasiewiczecfd3f72013-03-27 12:13:25 +0100460static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
461{
462 return container_of(to_config_group(item), struct f_serial_opts,
463 func_inst.group);
464}
465
466CONFIGFS_ATTR_STRUCT(f_serial_opts);
467static ssize_t f_obex_attr_show(struct config_item *item,
468 struct configfs_attribute *attr,
469 char *page)
470{
471 struct f_serial_opts *opts = to_f_serial_opts(item);
472 struct f_serial_opts_attribute *f_serial_opts_attr =
473 container_of(attr, struct f_serial_opts_attribute, attr);
474 ssize_t ret = 0;
475
476 if (f_serial_opts_attr->show)
477 ret = f_serial_opts_attr->show(opts, page);
478
479 return ret;
480}
481
482static void obex_attr_release(struct config_item *item)
483{
484 struct f_serial_opts *opts = to_f_serial_opts(item);
485
486 usb_put_function_instance(&opts->func_inst);
487}
488
489static struct configfs_item_operations obex_item_ops = {
490 .release = obex_attr_release,
491 .show_attribute = f_obex_attr_show,
492};
493
494static ssize_t f_obex_port_num_show(struct f_serial_opts *opts, char *page)
495{
496 return sprintf(page, "%u\n", opts->port_num);
497}
498
499static struct f_serial_opts_attribute f_obex_port_num =
500 __CONFIGFS_ATTR_RO(port_num, f_obex_port_num_show);
501
502static struct configfs_attribute *acm_attrs[] = {
503 &f_obex_port_num.attr,
504 NULL,
505};
506
507static struct config_item_type obex_func_type = {
508 .ct_item_ops = &obex_item_ops,
509 .ct_attrs = acm_attrs,
510 .ct_owner = THIS_MODULE,
511};
512
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100513static void obex_free_inst(struct usb_function_instance *f)
514{
515 struct f_serial_opts *opts;
516
517 opts = container_of(f, struct f_serial_opts, func_inst);
518 gserial_free_line(opts->port_num);
519 kfree(opts);
520}
521
522static struct usb_function_instance *obex_alloc_inst(void)
523{
524 struct f_serial_opts *opts;
525 int ret;
526
527 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
528 if (!opts)
529 return ERR_PTR(-ENOMEM);
530
531 opts->func_inst.free_func_inst = obex_free_inst;
532 ret = gserial_alloc_line(&opts->port_num);
533 if (ret) {
534 kfree(opts);
535 return ERR_PTR(ret);
536 }
Andrzej Pietrasiewiczecfd3f72013-03-27 12:13:25 +0100537 config_group_init_type_name(&opts->func_inst.group, "",
538 &obex_func_type);
Andrzej Pietrasiewicz1d8fc252013-03-21 15:33:42 +0100539
540 return &opts->func_inst;
541}
542
543static void obex_free(struct usb_function *f)
544{
545 struct f_obex *obex;
546
547 obex = func_to_obex(f);
548 kfree(obex);
549}
550
551static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
552{
553 obex_string_defs[OBEX_CTRL_IDX].id = 0;
554 usb_free_all_descriptors(f);
555}
556
557struct usb_function *obex_alloc(struct usb_function_instance *fi)
558{
559 struct f_obex *obex;
560 struct f_serial_opts *opts;
561
562 /* allocate and initialize one new instance */
563 obex = kzalloc(sizeof(*obex), GFP_KERNEL);
564 if (!obex)
565 return ERR_PTR(-ENOMEM);
566
567 opts = container_of(fi, struct f_serial_opts, func_inst);
568
569 obex->port_num = opts->port_num;
570
571 obex->port.connect = obex_connect;
572 obex->port.disconnect = obex_disconnect;
573
574 obex->port.func.name = "obex";
575 obex->port.func.strings = obex_strings;
576 /* descriptors are per-instance copies */
577 obex->port.func.bind = obex_bind;
578 obex->port.func.unbind = obex_unbind;
579 obex->port.func.set_alt = obex_set_alt;
580 obex->port.func.get_alt = obex_get_alt;
581 obex->port.func.disable = obex_disable;
582 obex->port.func.free_func = obex_free;
583
584 return &obex->port.func;
585}
586
587DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc);
588
589#endif
590
Felipe Balbi30867752008-08-18 17:39:30 -0700591MODULE_AUTHOR("Felipe Balbi");
592MODULE_LICENSE("GPL");