Remi Denis-Courmont | 953f551 | 2008-09-22 20:09:46 -0700 | [diff] [blame^] | 1 | Linux Phonet protocol family |
| 2 | ============================ |
| 3 | |
| 4 | Introduction |
| 5 | ------------ |
| 6 | |
| 7 | Phonet is a packet protocol used by Nokia cellular modems for both IPC |
| 8 | and RPC. With the Linux Phonet socket family, Linux host processes can |
| 9 | receive and send messages from/to the modem, or any other external |
| 10 | device attached to the modem. The modem takes care of routing. |
| 11 | |
| 12 | Phonet packets can be exchanged through various hardware connections |
| 13 | depending on the device, such as: |
| 14 | - USB with the CDC Phonet interface, |
| 15 | - infrared, |
| 16 | - Bluetooth, |
| 17 | - an RS232 serial port (with a dedicated "FBUS" line discipline), |
| 18 | - the SSI bus with some TI OMAP processors. |
| 19 | |
| 20 | |
| 21 | Packets format |
| 22 | -------------- |
| 23 | |
| 24 | Phonet packet have a common header as follow: |
| 25 | |
| 26 | struct phonethdr { |
| 27 | uint8_t pn_media; /* Media type (link-layer identifier) */ |
| 28 | uint8_t pn_rdev; /* Receiver device ID */ |
| 29 | uint8_t pn_sdev; /* Sender device ID */ |
| 30 | uint8_t pn_res; /* Resource ID or function */ |
| 31 | uint16_t pn_length; /* Big-endian message byte length (minus 6) */ |
| 32 | uint8_t pn_robj; /* Receiver object ID */ |
| 33 | uint8_t pn_sobj; /* Sender object ID */ |
| 34 | }; |
| 35 | |
| 36 | The device ID is split: the 6 higher order bits consitutes the device |
| 37 | address, while the 2 lower order bits are used for multiplexing, as are |
| 38 | the 8-bits object identifiers. As such, Phonet can be considered as a |
| 39 | network layer with 6 bits of address space and 10 bits for transport |
| 40 | protocol (much like port numbers in IP world). |
| 41 | |
| 42 | The modem always has address number zero. Each other device has a its |
| 43 | own 6-bits address. |
| 44 | |
| 45 | |
| 46 | Link layer |
| 47 | ---------- |
| 48 | |
| 49 | Phonet links are always point-to-point links. The link layer header |
| 50 | consists of a single Phonet media type byte. It uniquely identifies the |
| 51 | link through which the packet is transmitted, from the modem's |
| 52 | perspective. |
| 53 | |
| 54 | Linux Phonet network interfaces use a dedicated link layer type |
| 55 | (ETH_P_PHONET) which is out of the Ethernet type range. They can only |
| 56 | send and receive Phonet packets. |
| 57 | |
| 58 | Note that Phonet interfaces are not allowed to re-order packets, so |
| 59 | only the (default) Linux FIFO qdisc should be used with them. |
| 60 | |
| 61 | |
| 62 | Network layer |
| 63 | ------------- |
| 64 | |
| 65 | The Phonet socket address family maps the Phonet packet header: |
| 66 | |
| 67 | struct sockaddr_pn { |
| 68 | sa_family_t spn_family; /* AF_PHONET */ |
| 69 | uint8_t spn_obj; /* Object ID */ |
| 70 | uint8_t spn_dev; /* Device ID */ |
| 71 | uint8_t spn_resource; /* Resource or function */ |
| 72 | uint8_t spn_zero[...]; /* Padding */ |
| 73 | }; |
| 74 | |
| 75 | The resource field is only used when sending and receiving; |
| 76 | It is ignored by bind() and getsockname(). |
| 77 | |
| 78 | |
| 79 | Low-level datagram protocol |
| 80 | --------------------------- |
| 81 | |
| 82 | Applications can send Phonet messages using the Phonet datagram socket |
| 83 | protocol from the PF_PHONET family. Each socket is bound to one of the |
| 84 | 2^10 object IDs available, and can send and receive packets with any |
| 85 | other peer. |
| 86 | |
| 87 | struct sockaddr_pn addr = { .spn_family = AF_PHONET, }; |
| 88 | ssize_t len; |
| 89 | socklen_t addrlen = sizeof(addr); |
| 90 | int fd; |
| 91 | |
| 92 | fd = socket(PF_PHONET, SOCK_DGRAM, 0); |
| 93 | bind(fd, (struct sockaddr *)&addr, sizeof(addr)); |
| 94 | /* ... */ |
| 95 | |
| 96 | sendto(fd, msg, msglen, 0, (struct sockaddr *)&addr, sizeof(addr)); |
| 97 | len = recvfrom(fd, buf, sizeof(buf), 0, |
| 98 | (struct sockaddr *)&addr, &addrlen); |
| 99 | |
| 100 | This protocol follows the SOCK_DGRAM connection-less semantics. |
| 101 | However, connect() and getpeername() are not supported, as they did |
| 102 | not seem useful with Phonet usages (could be added easily). |
| 103 | |
| 104 | |
| 105 | Authors |
| 106 | ------- |
| 107 | |
| 108 | Linux Phonet was initially written by Sakari Ailus. |
| 109 | Other contributors include Mikä Liljeberg, Andras Domokos, |
| 110 | Carlos Chinea and Rémi Denis-Courmont. |
| 111 | Copyright (C) 2008 Nokia Corporation. |