phonet.txt 4.1 KB

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