Signed-off-by: Phoebe Buckheister <phoebe.buckheis...@itwm.fraunhofer.de>
---
 net/mac802154/Makefile    |    3 +-
 net/mac802154/llsec.c     |  139 +++++++++++++++++++++++++++++++++++++++++++++
 net/mac802154/llsec.h     |    9 +++
 net/mac802154/mac802154.h |    1 +
 4 files changed, 151 insertions(+), 1 deletion(-)
 create mode 100644 net/mac802154/llsec.c

diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile
index 15d62df5..9723d6f 100644
--- a/net/mac802154/Makefile
+++ b/net/mac802154/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_MAC802154)        += mac802154.o
-mac802154-objs         := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o 
wpan.o
+mac802154-objs         := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o \
+                          monitor.o wpan.o llsec.o
 
 ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/mac802154/llsec.c b/net/mac802154/llsec.c
new file mode 100644
index 0000000..5314522
--- /dev/null
+++ b/net/mac802154/llsec.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2014 Fraunhofer ITWM
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Written by:
+ * Phoebe Buckheister <phoebe.buckheis...@itwm.fraunhofer.de>
+ */
+
+#include <linux/err.h>
+#include <linux/bug.h>
+#include <linux/completion.h>
+#include <net/ieee802154.h>
+
+#include "mac802154.h"
+#include "llsec.h"
+
+void mac802154_llsec_init(struct mac802154_llsec *sec)
+{
+       memset(sec, 0, sizeof(*sec));
+
+       memset(&sec->params.default_key_source, 0xFF, IEEE802154_ADDR_LEN);
+
+       INIT_LIST_HEAD(&sec->table.security_levels);
+       INIT_LIST_HEAD(&sec->table.devices);
+       INIT_LIST_HEAD(&sec->table.keys);
+       hash_init(sec->devices_short);
+       hash_init(sec->devices_hw);
+       spin_lock_init(&sec->lock);
+}
+
+void mac802154_llsec_destroy(struct mac802154_llsec *sec)
+{
+       struct ieee802154_llsec_seclevel *sl, *sn;
+       struct ieee802154_llsec_device *dev, *dn;
+       struct ieee802154_llsec_key_entry *key, *kn;
+
+       list_for_each_entry_safe(sl, sn, &sec->table.security_levels, list) {
+               struct mac802154_llsec_seclevel *msl;
+
+               msl = container_of(sl, struct mac802154_llsec_seclevel, level);
+               list_del(&sl->list);
+               kfree(msl);
+       }
+
+       list_for_each_entry_safe(dev, dn, &sec->table.devices, list) {
+               struct mac802154_llsec_device *mdev;
+
+               mdev = container_of(dev, struct mac802154_llsec_device, dev);
+               list_del(&dev->list);
+               kfree(mdev);
+       }
+
+       list_for_each_entry_safe(key, kn, &sec->table.keys, list) {
+               struct mac802154_llsec_key *mkey;
+
+               mkey = container_of(key->key, struct mac802154_llsec_key, key);
+               list_del(&key->list);
+               llsec_key_put(mkey);
+               kfree(key);
+       }
+}
+
+
+
+int mac802154_llsec_get_params(struct mac802154_llsec *sec,
+                              struct ieee802154_llsec_params *params)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&sec->lock, flags);
+       *params = sec->params;
+       spin_unlock_irqrestore(&sec->lock, flags);
+
+       return 0;
+}
+
+int mac802154_llsec_set_params(struct mac802154_llsec *sec,
+                              const struct ieee802154_llsec_params *params,
+                              int changed)
+{
+       struct mac802154_llsec_key *key = NULL;
+       struct ieee802154_llsec_key_entry *pos;
+       unsigned long flags;
+
+       spin_lock_irqsave(&sec->lock, flags);
+
+       if (changed & IEEE802154_LLSEC_PARAM_OUT_KEY) {
+               list_for_each_entry(pos, &sec->table.keys, list) {
+                       if (!llsec_key_id_equal(&pos->id, &params->out_key))
+                               continue;
+
+                       key = container_of(pos->key, struct mac802154_llsec_key,
+                                          key);
+                       break;
+               }
+
+               if (!key) {
+                       spin_unlock_irqrestore(&sec->lock, flags);
+                       return -ENOENT;
+               }
+       }
+
+       if (changed & IEEE802154_LLSEC_PARAM_ENABLED)
+               sec->params.enabled = params->enabled;
+       if (changed & IEEE802154_LLSEC_PARAM_FRAME_COUNTER)
+               sec->params.frame_counter = params->frame_counter;
+       if (changed & IEEE802154_LLSEC_PARAM_OUT_LEVEL)
+               sec->params.out_level = params->out_level;
+       if (changed & IEEE802154_LLSEC_PARAM_OUT_KEY) {
+               sec->params.out_key = params->out_key;
+               sec->out_key = key;
+       }
+       if (changed & IEEE802154_LLSEC_PARAM_KEY_SOURCE)
+               sec->params.default_key_source = params->default_key_source;
+       if (changed & IEEE802154_LLSEC_PARAM_PAN_ID)
+               sec->params.pan_id = params->pan_id;
+       if (changed & IEEE802154_LLSEC_PARAM_HWADDR)
+               sec->params.hwaddr = params->hwaddr;
+       if (changed & IEEE802154_LLSEC_PARAM_COORD_HWADDR)
+               sec->params.coord_hwaddr = params->coord_hwaddr;
+       if (changed & IEEE802154_LLSEC_PARAM_COORD_SHORTADDR)
+               sec->params.coord_shortaddr = params->coord_shortaddr;
+
+       spin_unlock_irqrestore(&sec->lock, flags);
+
+       return 0;
+}
diff --git a/net/mac802154/llsec.h b/net/mac802154/llsec.h
index 80fb4a5..1315cf4 100644
--- a/net/mac802154/llsec.h
+++ b/net/mac802154/llsec.h
@@ -74,4 +74,13 @@ struct mac802154_llsec {
        spinlock_t lock;
 };
 
+void mac802154_llsec_init(struct mac802154_llsec *sec);
+void mac802154_llsec_destroy(struct mac802154_llsec *sec);
+
+int mac802154_llsec_get_params(struct mac802154_llsec *sec,
+                              struct ieee802154_llsec_params *params);
+int mac802154_llsec_set_params(struct mac802154_llsec *sec,
+                              const struct ieee802154_llsec_params *params,
+                              int changed);
+
 #endif /* MAC802154_LLSEC_H */
diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
index 28ef59c..e05f66e 100644
--- a/net/mac802154/mac802154.h
+++ b/net/mac802154/mac802154.h
@@ -23,6 +23,7 @@
 #ifndef MAC802154_H
 #define MAC802154_H
 
+#include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
 
 /* mac802154 device private data */
-- 
1.7.9.5


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to