From: Felix Varghese <felixvarg...@gmail.com>

This patch adds functions for invoking PIB set and get to the Netlink interface.

Signed-off-by: Felix Varghese <felixvarg...@gmail.com>
Signed-off-by: Prajosh Premdas <premdas.praj...@gmail.com>
---
 net/ieee802154/nl-mac.c    |  141 ++++++++++++++++++++++++++++++++++++++++++++
 net/ieee802154/nl_policy.c |    4 +
 2 files changed, 145 insertions(+), 0 deletions(-)

diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 2ace28b..c32c460 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -571,6 +571,145 @@ nla_put_failure:
 }
 EXPORT_SYMBOL(ieee802154_reset_confirm);
 
+int ieee802154_nl_get_confirm(struct net_device *dev, u8 PIBattr,
+                                                       void *PIBval, int size)
+{
+       struct sk_buff *msg;
+
+       msg = ieee802154_nl_create(0, IEEE802154_GET_CONF);
+       if (!msg)
+               return -ENOBUFS;
+
+       NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_PIB_ATTRIBUTE, PIBattr);
+
+       if (size >= 0) {
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, IEEE802154_SUCCESS);
+               NLA_PUT(msg, IEEE802154_ATTR_PIB_VALUE, size, PIBval);
+               NLA_PUT_U8(msg, IEEE802154_ATTR_PIB_SIZE, size);
+       } else{
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS,
+                                               IEEE802154_UNSUPPORTED_ATTR);
+       }
+
+       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+
+nla_put_failure:
+       nlmsg_free(msg);
+       return -ENOBUFS;
+}
+EXPORT_SYMBOL(ieee802154_nl_get_confirm);
+
+static int ieee802154_get_req(struct sk_buff *skb, struct genl_info *info)
+{
+       struct net_device *dev;
+       u8 PIB_Attribute;
+       int ret = 0;
+
+       if (!info->attrs[IEEE802154_ATTR_PIB_ATTRIBUTE])
+               return -EINVAL;
+
+       dev = ieee802154_nl_get_dev(info);
+       if (!dev) {
+               ret = -ENODEV;
+               goto error;
+       }
+
+       PIB_Attribute = nla_get_u8(info->attrs[IEEE802154_ATTR_PIB_ATTRIBUTE]);
+
+       if (!ieee802154_mlme_ops(dev)->get_req) {
+               ret = -EOPNOTSUPP;
+               goto error;
+       }
+
+       ret = ieee802154_mlme_ops(dev)->get_req(dev, PIB_Attribute);
+
+error:
+       dev_put(dev);
+       return ret;
+}
+
+int ieee802154_nl_set_confirm(struct net_device *dev, u8 PIBattr, int status)
+{
+       struct sk_buff *msg;
+
+       msg = ieee802154_nl_create(0, IEEE802154_SET_CONF);
+       if (!msg)
+               return -ENOBUFS;
+
+       NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_PIB_ATTRIBUTE, PIBattr);
+
+       switch (status) {
+       case 0:
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, IEEE802154_SUCCESS);
+               break;
+
+       case -EPERM:
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, IEEE802154_READ_ONLY);
+               break;
+
+       case -EINVAL:
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS,
+                                       IEEE802154_INVALID_PARAMETER);
+               break;
+
+       case -EOPNOTSUPP:
+               NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS,
+                                       IEEE802154_UNSUPPORTED_ATTR);
+               break;
+       }
+
+       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+
+nla_put_failure:
+       nlmsg_free(msg);
+       return -ENOBUFS;
+}
+EXPORT_SYMBOL(ieee802154_nl_set_confirm);
+
+static int ieee802154_set_req(struct sk_buff *skb, struct genl_info *info)
+{
+       struct net_device *dev;
+       u8 PIB_Attribute;
+       char *PIBvalue;
+       int ret = 0;
+       u8 len;
+
+       if (!info->attrs[IEEE802154_ATTR_PIB_ATTRIBUTE])
+               return -EINVAL;
+
+       dev = ieee802154_nl_get_dev(info);
+       if (!dev) {
+               ret = -ENODEV;
+               goto error;
+       }
+
+       PIB_Attribute = nla_get_u8(info->attrs[IEEE802154_ATTR_PIB_ATTRIBUTE]);
+       len = nla_len(info->attrs[IEEE802154_ATTR_PIB_VALUE]);
+
+       PIBvalue = kmalloc(sizeof(union pib_value_t), GFP_ATOMIC);
+       if (!PIBvalue) {
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       nla_memcpy(PIBvalue, info->attrs[IEEE802154_ATTR_PIB_VALUE], len);
+
+       if (!ieee802154_mlme_ops(dev)->set_req) {
+               ret = -EOPNOTSUPP;
+               goto error_free_mem;
+       }
+
+       ret = ieee802154_mlme_ops(dev)->set_req(dev, PIB_Attribute, PIBvalue);
+
+error_free_mem:
+       kfree(PIBvalue);
+error:
+       dev_put(dev);
+       return ret;
+}
+
 static int ieee802154_list_iface(struct sk_buff *skb,
        struct genl_info *info)
 {
@@ -634,6 +773,8 @@ cont:
 
 static struct genl_ops ieee802154_coordinator_ops[] = {
        IEEE802154_OP(IEEE802154_RESET_REQ, ieee802154_reset_req),
+       IEEE802154_OP(IEEE802154_GET_REQ, ieee802154_get_req),
+       IEEE802154_OP(IEEE802154_SET_REQ, ieee802154_set_req),
        IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
        IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
        IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
diff --git a/net/ieee802154/nl_policy.c b/net/ieee802154/nl_policy.c
index 9da1d72..143b3f6 100644
--- a/net/ieee802154/nl_policy.c
+++ b/net/ieee802154/nl_policy.c
@@ -54,5 +54,9 @@ const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX 
+ 1] = {
        [IEEE802154_ATTR_CHANNEL_PAGE_LIST] = { .len = 32 * 4, },
 
        [IEEE802154_ATTR_SET_DEFAULT_PIB] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_PIB_ATTRIBUTE] = { .type = NLA_U8, },
+       [IEEE802154_ATTR_PIB_VALUE] = { .type = NLA_UNSPEC,},
+       [IEEE802154_ATTR_PIB_SIZE] = { .type = NLA_U8, },
+
 };
 
-- 
1.7.4.1


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to