Here I present the conversion of everything that is required to provide
the equivalent of g_nokia.ko with configfs.

A branch will be available here (from 23rd May 2013, afternoon UTC):
git://git.infradead.org/users/kmpark/linux-samsung usb-gadget-configfs

v1..v2:

- don't unregister a network interface if it has not been registered before
- add phonet function description in Documentation/ABI

This series requires the following series to be applied:

http://comments.gmane.org/gmane.linux.usb.general/86773
http://comments.gmane.org/gmane.linux.usb.general/86783
http://www.spinics.net/lists/linux-usb/msg85307.html

BACKWARD COMPATIBILITY
======================

Please note that the old g_nokia.ko is still available and works.


USING THE NEW "GADGET"
======================

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based
gadgets (*).

Here is the description specific to using g_nokia.ko equivalent.

The old g_nokia.ko provides 4 functions:

- Phonet
- Obex (2 instances)
- ACM
- ECM

in 2 configurations, which contain this same set of functions,
but differ in MaxPower.

The procedure of setting up such a gadget with configfs is given
below with an example:

$ modprobe libcomposite
 
$ mount none cfg -t configfs
 
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
 
$ echo 0x01c8 > idProduct
$ echo 0x0421 > idVendor
$ mkdir strings/0x409
$ echo Nokia > strings/0x409/manufacturer
$ echo "N900 (PC-Suite Mode)" > strings/0x409/product
 
$ mkdir configs/c.1
$ echo 500 > configs/c.1/MaxPower
$ mkdir configs/c.1/strings/0x409
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
 
$ mkdir configs/c.2
$ echo 100 > configs/c.2/MaxPower
$ mkdir configs/c.2/strings/0x409
$ echo "Conf 2" > configs/c.2/strings/0x409/configuration
 
$ mkdir functions/phonet.pn0
$ mkdir functions/obex.obex1
$ mkdir functions/obex.obex2
$ mkdir functions/acm.tty0
$ mkdir functions/ecm.usb0
 
$ ln -s functions/phonet.pn0 configs/c.1
$ ln -s functions/obex.obex1 configs/c.1
$ ln -s functions/obex.obex2 configs/c.1
$ ln -s functions/acm.tty0 configs/c.1
$ ln -s functions/ecm.usb0 configs/c.1
 
$ ln -s functions/phonet.pn0 configs/c.2
$ ln -s functions/obex.obex1 configs/c.2
$ ln -s functions/obex.obex2 configs/c.2
$ ln -s functions/acm.tty0 configs/c.2
$ ln -s functions/ecm.usb0 configs/c.2
 
$ echo s3c-hsotg > UDC

The obex and acm functions provide only one, readonly, attribute port_num,
which contains their port number.
The phonet function provides only one, readonly, attribute ifname, which
contains the network interface name associated with the function.
The ecm function provides qmult, dev_addr, host_addr read-write attributes,
and ifname readonly attribute.
and after creating the functions/ecm.<instance name> it contains default
values: qmult is 5, dev_addr and host_addr are randomly selected.
Except for ifname they can be written to until the function is linked to a
configuration. The ifname is read-only and contains the name of the interface
which was assigned by the net core, e. g. usb0.

After unbinding the gadget with echo "" > UDC
the symbolic links in the configuration directory can be removed,
the strings/* subdirectories in the configuration directory can
be removed, the strings/* subdirectories at the gadget level can
be removed and the configs/* subdirectories can be removed.
The functions/* subdirectories can be removed.
After that the gadget directory can be removed.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS
====================

phonet)

It is not possible to test the SOCK_STREAM protocol without a specific piece
of hardware, so only SOCK_DGRAM has been tested. For the latter to work,
I had to apply the patch mentioned here:

http://www.spinics.net/lists/linux-usb/msg85689.html

For this to work, these tools are required

git://git.gitorious.org/meego-cellular/phonet-utils.git

On the host:

$ ./phonet -a 0x10 -i usbpn0
$ ./pnroute add 0x6c usbpn0
$./pnroute add 0x10 usbpn0
$ ifconfig usbpn0 up

On the device:

$ ./phonet -a 0x6c -i upnlink0
$ ./pnroute add 0x10 upnlink0
$ ifconfig upnlink0 up

Then a test program can be used:

http://www.spinics.net/lists/linux-usb/msg85690.html

On the device:

$ ./pnxmit -a 0x6c -r

On the host:

$ ./pnxmit -a 0x10 -s 0x6c

As a result some data should be sent from host to device.
Then the other way round:

On the host:

$ ./pnxmit -a 0x10 -r

On the device:

$ ./pnxmit -a 0x6c -s 0x10

obex)

On device: seriald -f /dev/ttyGS<Y> -s 1024
On host: serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
             -t<out endpoint addr> -r<in endpoint addr>

where seriald and serialc are Felipe's utilities found here:

https://git.gitorious.org/usb/usb-tools.git master

acm)

On host: cat > /dev/ttyACM<X>
On target: cat /dev/ttyGS<Y>

then the other way round

On target: cat > /dev/ttyGS<Y>
On host: cat /dev/ttyACM<X>

ecm)

On the device: ping <host's IP>
On the host: ping <device's IP>


Andrzej Pietrasiewicz (9):
  usb/gadget: f_obex: use usb_gstrings_attach
  usb/gadget: nokia: convert to new interface of f_obex
  usb/gadget: f_obex: remove compatibility layer
  usb/gadget: phonet: move global dev variable to its user
  usb/gadget: f_phonet: convert to new function interface with backward
    compatibility
  usb/gadget: nokia: convert to new interface of f_phonet
  usb/gadget: f_phonet: remove compatibility layer
  usb/gadget: nokia: convert to new interface of f_ecm
  usb/gadget: f_phonet: add configfs support

 .../ABI/testing/configfs-usb-gadget-phonet         |    8 +
 drivers/usb/gadget/Kconfig                         |   16 ++
 drivers/usb/gadget/Makefile                        |    2 +
 drivers/usb/gadget/f_obex.c                        |   75 +------
 drivers/usb/gadget/f_phonet.c                      |  177 +++++++++++++---
 drivers/usb/gadget/nokia.c                         |  235 +++++++++++++-------
 drivers/usb/gadget/u_phonet.h                      |   14 +-
 7 files changed, 351 insertions(+), 176 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-phonet

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to