diff options
Diffstat (limited to 'libnl_2')
-rw-r--r-- | libnl_2/Android.mk | 19 | ||||
-rw-r--r-- | libnl_2/attr.c | 22 | ||||
-rw-r--r-- | libnl_2/genl/genl.c | 32 | ||||
-rw-r--r-- | libnl_2/msg.c | 1 | ||||
-rw-r--r-- | libnl_2/socket.c | 12 |
5 files changed, 72 insertions, 14 deletions
diff --git a/libnl_2/Android.mk b/libnl_2/Android.mk index 1745f5a..deac9de 100644 --- a/libnl_2/Android.mk +++ b/libnl_2/Android.mk @@ -1,5 +1,11 @@ +####################################### +# * Netlink cache not implemented +# * Library is not thread safe +####################################### + LOCAL_PATH := $(call my-dir) + include $(CLEAR_VARS) LOCAL_SRC_FILES := \ @@ -22,9 +28,10 @@ LOCAL_MODULE := libnl_2 LOCAL_MODULE_TAGS := optional include $(BUILD_STATIC_LIBRARY) -####################################### -# Shared library currently unavailiable -# * Netlink cache not implemented -# * Library is not thread safe -####################################### - +include $(CLEAR_VARS) +LOCAL_SRC_FILES := +LOCAL_WHOLE_STATIC_LIBRARIES:= libnl_2 +LOCAL_SHARED_LIBRARIES:= liblog +LOCAL_MODULE := libnl_2 +LOCAL_MODULE_TAGS := optional +include $(BUILD_SHARED_LIBRARY) diff --git a/libnl_2/attr.c b/libnl_2/attr.c index f3a2b58..2ef7590 100644 --- a/libnl_2/attr.c +++ b/libnl_2/attr.c @@ -160,9 +160,31 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data) } return -EINVAL; +} + +/* Add 8 bit integer attribute to netlink message. */ +int nla_put_u8(struct nl_msg *msg, int attrtype, uint8_t value) +{ + return nla_put(msg, attrtype, sizeof(uint8_t), &value); +} + +/* Add 16 bit integer attribute to netlink message. */ +int nla_put_u16(struct nl_msg *msg, int attrtype, uint16_t value) +{ + return nla_put(msg, attrtype, sizeof(uint16_t), &value); +} +/* Add 32 bit integer attribute to netlink message. */ +int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value) +{ + return nla_put(msg, attrtype, sizeof(uint32_t), &value); } +/* Add 64 bit integer attribute to netlink message. */ +int nla_put_u64(struct nl_msg *msg, int attrtype, uint64_t value) +{ + return nla_put(msg, attrtype, sizeof(uint64_t), &value); +} /* Add nested attributes to netlink message. */ /* Takes the attributes found in the nested message and appends them diff --git a/libnl_2/genl/genl.c b/libnl_2/genl/genl.c index 2442993..1a39c6a 100644 --- a/libnl_2/genl/genl.c +++ b/libnl_2/genl/genl.c @@ -20,7 +20,10 @@ #include <unistd.h> #include <stdio.h> #include <sys/time.h> +#include <sys/socket.h> #include <linux/netlink.h> +#include <netlink/genl/ctrl.h> +#include <netlink/genl/family.h> #include "netlink-types.h" /* Get head of attribute data. */ @@ -250,7 +253,6 @@ error: struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache, \ const char *name) { - /* TODO: When will we release this memory ? */ struct genl_family *gf = (struct genl_family *) \ malloc(sizeof(struct genl_family)); if (!gf) @@ -262,7 +264,7 @@ struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache, \ /* Overriding cache pointer as family id for now */ gf->gf_id = (uint16_t) ((uint32_t) cache); - strcpy(gf->gf_name, "nl80211"); + strncpy(gf->gf_name, name, GENL_NAMSIZ); return gf; fail: @@ -272,15 +274,29 @@ fail: int genl_ctrl_resolve(struct nl_sock *sk, const char *name) { + struct nl_cache *cache = NULL; + struct genl_family *gf = NULL; + int id = -1; + /* Hack to support wpa_supplicant */ if (strcmp(name, "nlctrl") == 0) return NETLINK_GENERIC; - else { - int errsv = errno; - fprintf(stderr, \ - "Only nlctrl supported by genl_ctrl_resolve!\n"); - return -errsv; + + if (strcmp(name, "nl80211") != 0) { + fprintf(stderr, "%s is not supported\n", name); + return id; } -} + if (!genl_ctrl_alloc_cache(sk, &cache)) { + gf = genl_ctrl_search_by_name(cache, name); + if (gf) + id = genl_family_get_id(gf); + } + + if (gf) + genl_family_put(gf); + if (cache) + nl_cache_free(cache); + return id; +} diff --git a/libnl_2/msg.c b/libnl_2/msg.c index 283da6e..1303e8a 100644 --- a/libnl_2/msg.c +++ b/libnl_2/msg.c @@ -18,6 +18,7 @@ #include <malloc.h> #include <unistd.h> +#include <sys/socket.h> #include <linux/netlink.h> #include "netlink-types.h" diff --git a/libnl_2/socket.c b/libnl_2/socket.c index d906cac..e94eb9e 100644 --- a/libnl_2/socket.c +++ b/libnl_2/socket.c @@ -127,3 +127,15 @@ int nl_socket_get_fd(struct nl_sock *sk) { return sk->s_fd; } + +void nl_socket_set_cb(struct nl_sock *sk, struct nl_cb *cb) +{ + nl_cb_put(sk->s_cb); + sk->s_cb = cb; + nl_cb_get(cb); +} + +struct nl_cb *nl_socket_get_cb(struct nl_sock *sk) +{ + return nl_cb_get(sk->s_cb); +} |