Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 1 | Netlink Protocol Library |
| 2 | |
| 3 | This library is a clean room re-implementation of libnl 2.0 and |
| 4 | re-licensed under Apache 2.0. It was developed primarily to support |
| 5 | wpa_supplicant. However, with additional development can be extended |
| 6 | to support other netlink applications. |
| 7 | |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 8 | Netlink Protocol Format (RFC3549) |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 9 | |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 10 | +-----------------+-+-------------------+-+ |
| 11 | |Netlink Message |P| Generic Netlink |P| |
| 12 | | Header |A| Message Header |A| |
| 13 | |(struct nlmsghdr)|D|(struct genlmsghdr)|D| |
Dmitry Shmidt | 806ed3c | 2011-08-12 14:46:33 -0700 | [diff] [blame] | 14 | +-----------------+-+-------------------+-+-------------+ |
| 15 | |len:4|type:2|flags:2|seq:4 pid:4|cmd:1|ver:1|reserved:2| |
| 16 | +--------------------------------+----------------------+ |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 17 | +-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+ |
| 18 | |Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|...| |
| 19 | | #0 Header |A| #0 Payload |A| #1 Header |A| #1 Payload |A| | |
| 20 | | (struct nlattr) |D| (void) |D| (struct nlattr) |D| (void) |D| | |
| 21 | +-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+ |
Dmitry Shmidt | 806ed3c | 2011-08-12 14:46:33 -0700 | [diff] [blame] | 22 | |len:2(==4+payload)|type:2|payload|pad| |
| 23 | +-------------------------+-------+---+ |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 24 | |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 25 | NETLINK OVERVIEW |
| 26 | |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 27 | * Each netlink message consists of a bitstream with a netlink header. |
| 28 | * After this header a second header *can* be used specific to the netlink |
| 29 | family in use. This library was tested using the generic netlink |
| 30 | protocol defined by struct genlmsghdr to support nl80211. |
| 31 | * After the header(s) netlink attributes can be appended to the message |
| 32 | which hold can hold basic types such as unsigned integers and strings. |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 33 | * Attributes can also be nested. This is accomplished by calling "nla_nest_start" |
| 34 | which creates an empty attribute with nest attributes as its payload. Then to |
| 35 | close the nest, "nla_nest_end" is called. |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 36 | * All data structures in this implementation are byte-aligned (Currently 4 bytes). |
| 37 | * Acknowledgements (ACKs) are sent as NLMSG_ERROR netlink message types (0x2) and |
| 38 | have an error value of 0. |
| 39 | |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 40 | KNOWN ISSUES |
| 41 | |
| 42 | GENERAL |
| 43 | * Not tested for thread safety |
| 44 | |
| 45 | Android.mk |
Dmitry Shmidt | 806ed3c | 2011-08-12 14:46:33 -0700 | [diff] [blame] | 46 | * No dynamic library because of netlink cache not implemented and |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 47 | not tested for thread safety |
| 48 | |
| 49 | attr.c |
| 50 | * nla_parse - does not use nla_policy argument |
| 51 | |
| 52 | cache.c |
| 53 | * netlink cache not implemented and only supports one netlink family id |
| 54 | which is stored in the nl_cache pointer instead of an actual cache |
| 55 | |
| 56 | netlink.c |
| 57 | * nl_recvmsgs - does not support nl_cb_overwrite_recv() |
| 58 | * nl_recv - sets/unsets asynchronous socket flag |
| 59 | |
| 60 | SOURCE FILES |
| 61 | |
| 62 | * Android.mk - Android makefile |
| 63 | * README - This file |
| 64 | * attr.c - Netlink attributes |
| 65 | * cache.c - Netlink cache |
| 66 | * genl/family.c - Generic netlink family id |
| 67 | * genl/genl.c - Generic netlink |
| 68 | * handlers.c - Netlink callbacks |
| 69 | * msg.c - Netlink messages construction |
| 70 | * netlink.c - Netlink socket communication |
| 71 | * object.c - libnl object wrapper |
| 72 | * socket.c - Netlink kernel socket utils |
| 73 | |
| 74 | IMPORTANT HEADER FILES - NOTE: These are based on the the origin GPL libnl headers |
| 75 | |
| 76 | * netlink-types.h - Contains many important structs for libnl |
| 77 | to represent netlink objects |
| 78 | * netlink/netlink-kernel.h - Netlink kernel headers and field constants. |
| 79 | * netlink/msg.h - macros for iterating over netlink messages |
| 80 | * netlink/attr.h - netlink attribute constants, iteration macros and setters |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 81 | |
| 82 | REFERENCES |
Frank Maker | e065872 | 2011-08-04 15:41:47 -0700 | [diff] [blame] | 83 | |
Frank Maker | ed6b39c | 2011-05-23 21:14:58 -0700 | [diff] [blame] | 84 | * nl80211.h |
| 85 | * netlink_types.h |
| 86 | * $LINUX_KERNEL/net/wireless/nl80211.c |
| 87 | * http://www.infradead.org/~tgr/libnl/doc-3.0/index.html |
| 88 | * http://www.netfilter.org/projects/libmnl/doxygen/index.html |