This patch updated the netlink 802154 bindings to current net-next
mainline kernel.

Also add nl_updates from libteam to support netlink signed types which
the current libnl3 doesn't support.

Signed-off-by: Alexander Aring <alex.ar...@gmail.com>
---
 include/nl802154.h   |  49 ++++++++++++++++++++++-
 include/nl_updates.h |  75 ++++++++++++++++++++++++++++++++++++
 lib/nl_policy.c      |  29 +++++++++++++-
 src/Makefile.am      |   2 +-
 src/nl_updates.c     | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 258 insertions(+), 4 deletions(-)
 create mode 100644 include/nl_updates.h
 create mode 100644 src/nl_updates.c

diff --git a/include/nl802154.h b/include/nl802154.h
index ce1e6a1..5dce54b 100644
--- a/include/nl802154.h
+++ b/include/nl802154.h
@@ -21,6 +21,8 @@
 #ifndef NL802154_H
 #define NL802154_H
 
+#include "nl_updates.h"
+
 #define IEEE802154_NL_NAME "802.15.4 MAC"
 #define IEEE802154_MCAST_COORD_NAME "coordinator"
 #define IEEE802154_MCAST_BEACON_NAME "beacon"
@@ -70,6 +72,32 @@ enum {
        IEEE802154_ATTR_PHY_NAME,
        IEEE802154_ATTR_DEV_TYPE,
 
+       IEEE802154_ATTR_TXPOWER,
+       IEEE802154_ATTR_LBT_ENABLED,
+       IEEE802154_ATTR_CCA_MODE,
+       IEEE802154_ATTR_CCA_ED_LEVEL,
+       IEEE802154_ATTR_CSMA_RETRIES,
+       IEEE802154_ATTR_CSMA_MIN_BE,
+       IEEE802154_ATTR_CSMA_MAX_BE,
+
+       IEEE802154_ATTR_FRAME_RETRIES,
+
+       IEEE802154_ATTR_LLSEC_ENABLED,
+       IEEE802154_ATTR_LLSEC_SECLEVEL,
+       IEEE802154_ATTR_LLSEC_KEY_MODE,
+       IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT,
+       IEEE802154_ATTR_LLSEC_KEY_SOURCE_EXTENDED,
+       IEEE802154_ATTR_LLSEC_KEY_ID,
+       IEEE802154_ATTR_LLSEC_FRAME_COUNTER,
+       IEEE802154_ATTR_LLSEC_KEY_BYTES,
+       IEEE802154_ATTR_LLSEC_KEY_USAGE_FRAME_TYPES,
+       IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS,
+       IEEE802154_ATTR_LLSEC_FRAME_TYPE,
+       IEEE802154_ATTR_LLSEC_CMD_FRAME_ID,
+       IEEE802154_ATTR_LLSEC_SECLEVELS,
+       IEEE802154_ATTR_LLSEC_DEV_OVERRIDE,
+       IEEE802154_ATTR_LLSEC_DEV_KEY_MODE,
+
        __IEEE802154_ATTR_MAX,
 };
 
@@ -122,15 +150,34 @@ enum {
        IEEE802154_ADD_IFACE,
        IEEE802154_DEL_IFACE,
 
+       IEEE802154_SET_MACPARAMS,
+
+       IEEE802154_LLSEC_GETPARAMS,
+       IEEE802154_LLSEC_SETPARAMS,
+       IEEE802154_LLSEC_LIST_KEY,
+       IEEE802154_LLSEC_ADD_KEY,
+       IEEE802154_LLSEC_DEL_KEY,
+       IEEE802154_LLSEC_LIST_DEV,
+       IEEE802154_LLSEC_ADD_DEV,
+       IEEE802154_LLSEC_DEL_DEV,
+       IEEE802154_LLSEC_LIST_DEVKEY,
+       IEEE802154_LLSEC_ADD_DEVKEY,
+       IEEE802154_LLSEC_DEL_DEVKEY,
+       IEEE802154_LLSEC_LIST_SECLEVEL,
+       IEEE802154_LLSEC_ADD_SECLEVEL,
+       IEEE802154_LLSEC_DEL_SECLEVEL,
+
        __IEEE802154_CMD_MAX,
 };
 
 #define IEEE802154_CMD_MAX (__IEEE802154_CMD_MAX - 1)
 
 enum {
+       __IEEE802154_DEV_INVALID = -1,
+
        IEEE802154_DEV_WPAN,
        IEEE802154_DEV_MONITOR,
-       IEEE802154_DEV_SMAC,
+
        __IEEE802154_DEV_MAX,
 };
 
diff --git a/include/nl_updates.h b/include/nl_updates.h
new file mode 100644
index 0000000..066d5bb
--- /dev/null
+++ b/include/nl_updates.h
@@ -0,0 +1,75 @@
+/*
+ *   lib/nl_updates.h - Updates to libnl which are not synced from kernel yet
+ *   Copyright (C) 2012-2013 Jiri Pirko <j...@resnulli.us>
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 
 USA
+ */
+
+#ifndef _NL_UPDATES_H_
+#define _NL_UPDATES_H_
+
+#ifndef NLA_BINARY
+#define NLA_BINARY 11
+#endif
+
+#ifndef NLA_S8
+/*
+ * Presume that libnl will add all types and relevant puts/gets at once
+ * so check only for NLA_S8.
+ */
+#define NLA_S8 12
+#define NLA_S16 13
+#define NLA_S32 14
+#define NLA_S64 15
+
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value.
+ */
+#define NLA_PUT_S8(msg, attrtype, value) \
+       NLA_PUT_TYPE(msg, int8_t, attrtype, value)
+
+/**
+ * Add 16 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value.
+ */
+#define NLA_PUT_S16(msg, attrtype, value) \
+       NLA_PUT_TYPE(msg, int16_t, attrtype, value)
+
+/**
+ * Add 32 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value.
+ */
+#define NLA_PUT_S32(msg, attrtype, value) \
+       NLA_PUT_TYPE(msg, int32_t, attrtype, value)
+
+/**
+ * Add 64 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value.
+ */
+#define NLA_PUT_S64(msg, attrtype, value) \
+       NLA_PUT_TYPE(msg, int64_t, attrtype, value)
+
+#endif
+
+#endif /* _NL_UPDATES_H_ */
diff --git a/lib/nl_policy.c b/lib/nl_policy.c
index d82b866..337610f 100644
--- a/lib/nl_policy.c
+++ b/lib/nl_policy.c
@@ -20,7 +20,7 @@
 
 #include <netlink/netlink.h>
 #include <netlink/attr.h>
-#include <nl802154.h>
+#include "nl802154.h"
 
 #define NLA_HW_ADDR NLA_U64
 
@@ -28,7 +28,6 @@ struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] 
= {
        [IEEE802154_ATTR_DEV_NAME] = { .type = NLA_STRING, },
        [IEEE802154_ATTR_DEV_INDEX] = { .type = NLA_U32, },
        [IEEE802154_ATTR_PHY_NAME] = { .type = NLA_STRING, },
-       [IEEE802154_ATTR_DEV_TYPE] = { .type = NLA_U8, },
 
        [IEEE802154_ATTR_STATUS] = { .type = NLA_U8, },
        [IEEE802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, },
@@ -53,5 +52,31 @@ struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] 
= {
        [IEEE802154_ATTR_DURATION] = { .type = NLA_U8, },
        [IEEE802154_ATTR_ED_LIST] = { .minlen = 27, .maxlen = 27, },
        [IEEE802154_ATTR_CHANNEL_PAGE_LIST] = { .minlen = 0, .maxlen = 32 * 4, 
},
+
+       [IEEE802154_ATTR_TXPOWER] = { .type = NLA_S8, },
+       [IEEE802154_ATTR_LBT_ENABLED] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_CCA_MODE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_CCA_ED_LEVEL] = { .type = NLA_S32, },
+       [IEEE802154_ATTR_CSMA_RETRIES] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_CSMA_MIN_BE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_CSMA_MAX_BE] = { .type = NLA_U8, },
+
+       [IEEE802154_ATTR_FRAME_RETRIES] = { .type = NLA_S8, },
+
+       [IEEE802154_ATTR_LLSEC_ENABLED] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_SECLEVEL] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_KEY_MODE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT] = { .type = NLA_U32, },
+       [IEEE802154_ATTR_LLSEC_KEY_SOURCE_EXTENDED] = { .type = NLA_HW_ADDR, },
+       [IEEE802154_ATTR_LLSEC_KEY_ID] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_FRAME_COUNTER] = { .type = NLA_U32 },
+       [IEEE802154_ATTR_LLSEC_KEY_BYTES] = { .minlen = 16, .maxlen = 16, },
+       [IEEE802154_ATTR_LLSEC_KEY_USAGE_FRAME_TYPES] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS] = { .minlen = 258 / 8, 
.maxlen = 258 / 8, },
+       [IEEE802154_ATTR_LLSEC_FRAME_TYPE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_CMD_FRAME_ID] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_SECLEVELS] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_DEV_OVERRIDE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_LLSEC_DEV_KEY_MODE] = { .type = NLA_U8, },
 };
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 46c4017..129e13f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,7 @@ EXTRA_DIST = $(manpages)
 
 izattach_SOURCES = serial.c
 
-iz_SOURCES = iz.c iz-common.c iz-mac.c iz-phy.c
+iz_SOURCES = iz.c iz-common.c iz-mac.c iz-phy.c nl_updates.c
 noinst_HEADERS = iz.h
 
 izcoordinator_SOURCES = coordinator.c
diff --git a/src/nl_updates.c b/src/nl_updates.c
new file mode 100644
index 0000000..31012a8
--- /dev/null
+++ b/src/nl_updates.c
@@ -0,0 +1,107 @@
+
+#include <netlink/attr.h>
+#include <netlink/netlink.h>
+
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+static inline int nla_put_s8(struct nl_msg *msg, int attrtype, int8_t value)
+{
+       return nla_put(msg, attrtype, sizeof(int8_t), &value);
+}
+
+/**
+ * Return value of 8 bit signed integer attribute.
+ * @arg nla            8 bit signed integer attribute
+ *
+ * @return Payload as 8 bit signed integer.
+ */
+int8_t nla_get_s8(struct nlattr *nla)
+{
+       return *(int8_t *) nla_data(nla);
+}
+
+/**
+ * Add 16 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+int nla_put_s16(struct nl_msg *msg, int attrtype, int16_t value)
+{
+       return nla_put(msg, attrtype, sizeof(int16_t), &value);
+}
+
+/**
+ * Return payload of 16 bit signed integer attribute.
+ * @arg nla            16 bit signed integer attribute
+ *
+ * @return Payload as 16 bit signed integer.
+ */
+int16_t nla_get_s16(struct nlattr *nla)
+{
+       return *(int16_t *) nla_data(nla);
+}
+
+/**
+ * Add 32 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+int nla_put_s32(struct nl_msg *msg, int attrtype, int32_t value)
+{
+       return nla_put(msg, attrtype, sizeof(int32_t), &value);
+}
+
+/**
+ * Return payload of 32 bit signed integer attribute.
+ * @arg nla            32 bit signed integer attribute.
+ *
+ * @return Payload as 32 bit signed integer.
+ */
+int32_t nla_get_s32(struct nlattr *nla)
+{
+       return *(int32_t *) nla_data(nla);
+}
+
+/**
+ * Add 64 bit signed integer attribute to netlink message.
+ * @arg msg            Netlink message.
+ * @arg attrtype       Attribute type.
+ * @arg value          Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+int nla_put_s64(struct nl_msg *msg, int attrtype, int64_t value)
+{
+       return nla_put(msg, attrtype, sizeof(int64_t), &value);
+}
+
+/**
+ * Return payload of u64 attribute
+ * @arg nla            u64 netlink attribute
+ *
+ * @return Payload as 64 bit signed integer.
+ */
+int64_t nla_get_s64(struct nlattr *nla)
+{
+       int64_t tmp;
+
+       nla_memcpy(&tmp, nla, sizeof(tmp));
+
+       return tmp;
+}
-- 
2.0.1


------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to