2 * HWSIM IEEE 802.15.4 interface
4 * (C) 2018 Mojatau, Alexander Aring <aring@mojatau.com>
5 * Copyright 2007-2012 Siemens AG
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * Based on fakelb, original Written by:
17 * Sergey Lapin <slapin@ossfans.org>
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
22 #include <linux/module.h>
23 #include <linux/timer.h>
24 #include <linux/platform_device.h>
25 #include <linux/rtnetlink.h>
26 #include <linux/netdevice.h>
27 #include <linux/device.h>
28 #include <linux/spinlock.h>
29 #include <net/mac802154.h>
30 #include <net/cfg802154.h>
31 #include <net/genetlink.h>
32 #include "mac802154_hwsim.h"
34 MODULE_DESCRIPTION("Software simulator of IEEE 802.15.4 radio(s) for mac802154");
35 MODULE_LICENSE("GPL");
37 static LIST_HEAD(hwsim_phys);
38 static DEFINE_MUTEX(hwsim_phys_lock);
40 static LIST_HEAD(hwsim_ifup_phys);
42 static struct platform_device *mac802154hwsim_dev;
44 /* MAC802154_HWSIM netlink family */
45 static struct genl_family hwsim_genl_family;
47 static int hwsim_radio_idx;
49 enum hwsim_multicast_groups {
53 static const struct genl_multicast_group hwsim_mcgrps[] = {
54 [HWSIM_MCGRP_CONFIG] = { .name = "config", },
64 struct hwsim_edge_info {
71 struct hwsim_phy *endpoint;
72 struct hwsim_edge_info __rcu *info;
74 struct list_head list;
79 struct ieee802154_hw *hw;
82 struct hwsim_pib __rcu *pib;
85 struct list_head edges;
87 struct list_head list;
88 struct list_head list_ifup;
91 static int hwsim_add_one(struct genl_info *info, struct device *dev,
93 static void hwsim_del(struct hwsim_phy *phy);
95 static int hwsim_hw_ed(struct ieee802154_hw *hw, u8 *level)
102 static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
104 struct hwsim_phy *phy = hw->priv;
105 struct hwsim_pib *pib, *pib_old;
107 pib = kzalloc(sizeof(*pib), GFP_KERNEL);
112 pib->channel = channel;
114 pib_old = rtnl_dereference(phy->pib);
115 rcu_assign_pointer(phy->pib, pib);
116 kfree_rcu(pib_old, rcu);
120 static int hwsim_hw_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
122 struct hwsim_phy *current_phy = hw->priv;
123 struct hwsim_pib *current_pib, *endpoint_pib;
124 struct hwsim_edge_info *einfo;
125 struct hwsim_edge *e;
127 WARN_ON(current_phy->suspended);
130 current_pib = rcu_dereference(current_phy->pib);
131 list_for_each_entry_rcu(e, ¤t_phy->edges, list) {
132 /* Can be changed later in rx_irqsafe, but this is only a
133 * performance tweak. Received radio should drop the frame
134 * in mac802154 stack anyway... so we don't need to be
135 * 100% of locking here to check on suspended
137 if (e->endpoint->suspended)
140 endpoint_pib = rcu_dereference(e->endpoint->pib);
141 if (current_pib->page == endpoint_pib->page &&
142 current_pib->channel == endpoint_pib->channel) {
143 struct sk_buff *newskb = pskb_copy(skb, GFP_ATOMIC);
145 einfo = rcu_dereference(e->info);
147 ieee802154_rx_irqsafe(e->endpoint->hw, newskb,
153 ieee802154_xmit_complete(hw, skb, false);
157 static int hwsim_hw_start(struct ieee802154_hw *hw)
159 struct hwsim_phy *phy = hw->priv;
161 phy->suspended = false;
162 list_add_rcu(&phy->list_ifup, &hwsim_ifup_phys);
168 static void hwsim_hw_stop(struct ieee802154_hw *hw)
170 struct hwsim_phy *phy = hw->priv;
172 phy->suspended = true;
173 list_del_rcu(&phy->list_ifup);
178 hwsim_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
183 static const struct ieee802154_ops hwsim_ops = {
184 .owner = THIS_MODULE,
185 .xmit_async = hwsim_hw_xmit,
187 .set_channel = hwsim_hw_channel,
188 .start = hwsim_hw_start,
189 .stop = hwsim_hw_stop,
190 .set_promiscuous_mode = hwsim_set_promiscuous_mode,
193 static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
195 return hwsim_add_one(info, &mac802154hwsim_dev->dev, false);
198 static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
200 struct hwsim_phy *phy, *tmp;
203 if (!info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID])
206 idx = nla_get_u32(info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID]);
208 mutex_lock(&hwsim_phys_lock);
209 list_for_each_entry_safe(phy, tmp, &hwsim_phys, list) {
210 if (idx == phy->idx) {
212 mutex_unlock(&hwsim_phys_lock);
216 mutex_unlock(&hwsim_phys_lock);
221 static int append_radio_msg(struct sk_buff *skb, struct hwsim_phy *phy)
223 struct nlattr *nl_edges, *nl_edge;
224 struct hwsim_edge_info *einfo;
225 struct hwsim_edge *e;
228 ret = nla_put_u32(skb, MAC802154_HWSIM_ATTR_RADIO_ID, phy->idx);
233 if (list_empty(&phy->edges)) {
238 nl_edges = nla_nest_start(skb, MAC802154_HWSIM_ATTR_RADIO_EDGES);
244 list_for_each_entry_rcu(e, &phy->edges, list) {
245 nl_edge = nla_nest_start(skb, MAC802154_HWSIM_ATTR_RADIO_EDGE);
248 nla_nest_cancel(skb, nl_edges);
252 ret = nla_put_u32(skb, MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID,
256 nla_nest_cancel(skb, nl_edge);
257 nla_nest_cancel(skb, nl_edges);
261 einfo = rcu_dereference(e->info);
262 ret = nla_put_u8(skb, MAC802154_HWSIM_EDGE_ATTR_LQI,
266 nla_nest_cancel(skb, nl_edge);
267 nla_nest_cancel(skb, nl_edges);
271 nla_nest_end(skb, nl_edge);
275 nla_nest_end(skb, nl_edges);
280 static int hwsim_get_radio(struct sk_buff *skb, struct hwsim_phy *phy,
282 struct netlink_callback *cb, int flags)
287 hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags,
288 MAC802154_HWSIM_CMD_GET_RADIO);
293 genl_dump_check_consistent(cb, hdr);
295 res = append_radio_msg(skb, phy);
299 genlmsg_end(skb, hdr);
303 genlmsg_cancel(skb, hdr);
307 static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info)
309 struct hwsim_phy *phy;
311 int idx, res = -ENODEV;
313 if (!info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID])
315 idx = nla_get_u32(info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID]);
317 mutex_lock(&hwsim_phys_lock);
318 list_for_each_entry(phy, &hwsim_phys, list) {
322 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
328 res = hwsim_get_radio(skb, phy, info->snd_portid,
329 info->snd_seq, NULL, 0);
335 res = genlmsg_reply(skb, info);
340 mutex_unlock(&hwsim_phys_lock);
345 static int hwsim_dump_radio_nl(struct sk_buff *skb,
346 struct netlink_callback *cb)
348 int idx = cb->args[0];
349 struct hwsim_phy *phy;
352 mutex_lock(&hwsim_phys_lock);
354 if (idx == hwsim_radio_idx)
357 list_for_each_entry(phy, &hwsim_phys, list) {
361 res = hwsim_get_radio(skb, phy, NETLINK_CB(cb->skb).portid,
362 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
372 mutex_unlock(&hwsim_phys_lock);
376 /* caller need to held hwsim_phys_lock */
377 static struct hwsim_phy *hwsim_get_radio_by_id(uint32_t idx)
379 struct hwsim_phy *phy;
381 list_for_each_entry(phy, &hwsim_phys, list) {
389 static const struct nla_policy hwsim_edge_policy[MAC802154_HWSIM_EDGE_ATTR_MAX + 1] = {
390 [MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID] = { .type = NLA_U32 },
391 [MAC802154_HWSIM_EDGE_ATTR_LQI] = { .type = NLA_U8 },
394 static struct hwsim_edge *hwsim_alloc_edge(struct hwsim_phy *endpoint, u8 lqi)
396 struct hwsim_edge_info *einfo;
397 struct hwsim_edge *e;
399 e = kzalloc(sizeof(*e), GFP_KERNEL);
403 einfo = kzalloc(sizeof(*einfo), GFP_KERNEL);
410 rcu_assign_pointer(e->info, einfo);
411 e->endpoint = endpoint;
416 static void hwsim_free_edge(struct hwsim_edge *e)
418 struct hwsim_edge_info *einfo;
421 einfo = rcu_dereference(e->info);
424 kfree_rcu(einfo, rcu);
428 static int hwsim_new_edge_nl(struct sk_buff *msg, struct genl_info *info)
430 struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX + 1];
431 struct hwsim_phy *phy_v0, *phy_v1;
432 struct hwsim_edge *e;
435 if (!info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID] ||
436 !info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE])
439 if (nla_parse_nested(edge_attrs, MAC802154_HWSIM_EDGE_ATTR_MAX,
440 info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE],
441 hwsim_edge_policy, NULL))
444 if (!edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID])
447 v0 = nla_get_u32(info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID]);
448 v1 = nla_get_u32(edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID]);
453 mutex_lock(&hwsim_phys_lock);
454 phy_v0 = hwsim_get_radio_by_id(v0);
456 mutex_unlock(&hwsim_phys_lock);
460 phy_v1 = hwsim_get_radio_by_id(v1);
462 mutex_unlock(&hwsim_phys_lock);
467 list_for_each_entry_rcu(e, &phy_v0->edges, list) {
468 if (e->endpoint->idx == v1) {
469 mutex_unlock(&hwsim_phys_lock);
476 e = hwsim_alloc_edge(phy_v1, 0xff);
478 mutex_unlock(&hwsim_phys_lock);
481 list_add_rcu(&e->list, &phy_v0->edges);
482 /* wait until changes are done under hwsim_phys_lock lock
483 * should prevent of calling this function twice while
484 * edges list has not the changes yet.
487 mutex_unlock(&hwsim_phys_lock);
492 static int hwsim_del_edge_nl(struct sk_buff *msg, struct genl_info *info)
494 struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX + 1];
495 struct hwsim_phy *phy_v0;
496 struct hwsim_edge *e;
499 if (!info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID] ||
500 !info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE])
503 if (nla_parse_nested(edge_attrs, MAC802154_HWSIM_EDGE_ATTR_MAX,
504 info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE],
505 hwsim_edge_policy, NULL))
508 if (!edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID])
511 v0 = nla_get_u32(info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID]);
512 v1 = nla_get_u32(edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID]);
514 mutex_lock(&hwsim_phys_lock);
515 phy_v0 = hwsim_get_radio_by_id(v0);
517 mutex_unlock(&hwsim_phys_lock);
522 list_for_each_entry_rcu(e, &phy_v0->edges, list) {
523 if (e->endpoint->idx == v1) {
525 list_del_rcu(&e->list);
527 /* same again - wait until list changes are done */
529 mutex_unlock(&hwsim_phys_lock);
535 mutex_unlock(&hwsim_phys_lock);
540 static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)
542 struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX + 1];
543 struct hwsim_edge_info *einfo;
544 struct hwsim_phy *phy_v0;
545 struct hwsim_edge *e;
549 if (!info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID] ||
550 !info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE])
553 if (nla_parse_nested(edge_attrs, MAC802154_HWSIM_EDGE_ATTR_MAX,
554 info->attrs[MAC802154_HWSIM_ATTR_RADIO_EDGE],
555 hwsim_edge_policy, NULL))
558 if (!edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID] ||
559 !edge_attrs[MAC802154_HWSIM_EDGE_ATTR_LQI])
562 v0 = nla_get_u32(info->attrs[MAC802154_HWSIM_ATTR_RADIO_ID]);
563 v1 = nla_get_u32(edge_attrs[MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID]);
564 lqi = nla_get_u8(edge_attrs[MAC802154_HWSIM_EDGE_ATTR_LQI]);
566 mutex_lock(&hwsim_phys_lock);
567 phy_v0 = hwsim_get_radio_by_id(v0);
569 mutex_unlock(&hwsim_phys_lock);
573 einfo = kzalloc(sizeof(*einfo), GFP_KERNEL);
575 mutex_unlock(&hwsim_phys_lock);
580 list_for_each_entry_rcu(e, &phy_v0->edges, list) {
581 if (e->endpoint->idx == v1) {
583 rcu_assign_pointer(e->info, einfo);
585 mutex_unlock(&hwsim_phys_lock);
592 mutex_unlock(&hwsim_phys_lock);
597 /* MAC802154_HWSIM netlink policy */
599 static const struct nla_policy hwsim_genl_policy[MAC802154_HWSIM_ATTR_MAX + 1] = {
600 [MAC802154_HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 },
601 [MAC802154_HWSIM_ATTR_RADIO_EDGE] = { .type = NLA_NESTED },
602 [MAC802154_HWSIM_ATTR_RADIO_EDGES] = { .type = NLA_NESTED },
605 /* Generic Netlink operations array */
606 static const struct genl_ops hwsim_nl_ops[] = {
608 .cmd = MAC802154_HWSIM_CMD_NEW_RADIO,
609 .policy = hwsim_genl_policy,
610 .doit = hwsim_new_radio_nl,
611 .flags = GENL_UNS_ADMIN_PERM,
614 .cmd = MAC802154_HWSIM_CMD_DEL_RADIO,
615 .policy = hwsim_genl_policy,
616 .doit = hwsim_del_radio_nl,
617 .flags = GENL_UNS_ADMIN_PERM,
620 .cmd = MAC802154_HWSIM_CMD_GET_RADIO,
621 .policy = hwsim_genl_policy,
622 .doit = hwsim_get_radio_nl,
623 .dumpit = hwsim_dump_radio_nl,
626 .cmd = MAC802154_HWSIM_CMD_NEW_EDGE,
627 .policy = hwsim_genl_policy,
628 .doit = hwsim_new_edge_nl,
629 .flags = GENL_UNS_ADMIN_PERM,
632 .cmd = MAC802154_HWSIM_CMD_DEL_EDGE,
633 .policy = hwsim_genl_policy,
634 .doit = hwsim_del_edge_nl,
635 .flags = GENL_UNS_ADMIN_PERM,
638 .cmd = MAC802154_HWSIM_CMD_SET_EDGE,
639 .policy = hwsim_genl_policy,
640 .doit = hwsim_set_edge_lqi,
641 .flags = GENL_UNS_ADMIN_PERM,
645 static struct genl_family hwsim_genl_family __ro_after_init = {
646 .name = "MAC802154_HWSIM",
648 .maxattr = MAC802154_HWSIM_ATTR_MAX,
649 .module = THIS_MODULE,
651 .n_ops = ARRAY_SIZE(hwsim_nl_ops),
652 .mcgrps = hwsim_mcgrps,
653 .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
656 static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
657 struct genl_info *info)
660 genl_notify(&hwsim_genl_family, mcast_skb, info,
661 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
663 genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0,
664 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
667 static void hwsim_mcast_new_radio(struct genl_info *info, struct hwsim_phy *phy)
669 struct sk_buff *mcast_skb;
672 mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
676 data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
677 MAC802154_HWSIM_CMD_NEW_RADIO);
681 if (append_radio_msg(mcast_skb, phy) < 0)
684 genlmsg_end(mcast_skb, data);
686 hwsim_mcast_config_msg(mcast_skb, info);
690 genlmsg_cancel(mcast_skb, data);
691 nlmsg_free(mcast_skb);
694 static void hwsim_edge_unsubscribe_me(struct hwsim_phy *phy)
696 struct hwsim_phy *tmp;
697 struct hwsim_edge *e;
700 /* going to all phy edges and remove phy from it */
701 list_for_each_entry(tmp, &hwsim_phys, list) {
702 list_for_each_entry_rcu(e, &tmp->edges, list) {
703 if (e->endpoint->idx == phy->idx) {
704 list_del_rcu(&e->list);
714 static int hwsim_subscribe_all_others(struct hwsim_phy *phy)
716 struct hwsim_phy *sub;
717 struct hwsim_edge *e;
719 list_for_each_entry(sub, &hwsim_phys, list) {
720 e = hwsim_alloc_edge(sub, 0xff);
724 list_add_rcu(&e->list, &phy->edges);
727 list_for_each_entry(sub, &hwsim_phys, list) {
728 e = hwsim_alloc_edge(phy, 0xff);
732 list_add_rcu(&e->list, &sub->edges);
738 hwsim_edge_unsubscribe_me(phy);
741 list_for_each_entry_rcu(e, &phy->edges, list) {
742 list_del_rcu(&e->list);
749 static int hwsim_add_one(struct genl_info *info, struct device *dev,
752 struct ieee802154_hw *hw;
753 struct hwsim_phy *phy;
754 struct hwsim_pib *pib;
758 idx = hwsim_radio_idx++;
760 hw = ieee802154_alloc_hw(sizeof(*phy), &hwsim_ops);
767 /* 868 MHz BPSK 802.15.4-2003 */
768 hw->phy->supported.channels[0] |= 1;
769 /* 915 MHz BPSK 802.15.4-2003 */
770 hw->phy->supported.channels[0] |= 0x7fe;
771 /* 2.4 GHz O-QPSK 802.15.4-2003 */
772 hw->phy->supported.channels[0] |= 0x7FFF800;
773 /* 868 MHz ASK 802.15.4-2006 */
774 hw->phy->supported.channels[1] |= 1;
775 /* 915 MHz ASK 802.15.4-2006 */
776 hw->phy->supported.channels[1] |= 0x7fe;
777 /* 868 MHz O-QPSK 802.15.4-2006 */
778 hw->phy->supported.channels[2] |= 1;
779 /* 915 MHz O-QPSK 802.15.4-2006 */
780 hw->phy->supported.channels[2] |= 0x7fe;
781 /* 2.4 GHz CSS 802.15.4a-2007 */
782 hw->phy->supported.channels[3] |= 0x3fff;
783 /* UWB Sub-gigahertz 802.15.4a-2007 */
784 hw->phy->supported.channels[4] |= 1;
785 /* UWB Low band 802.15.4a-2007 */
786 hw->phy->supported.channels[4] |= 0x1e;
787 /* UWB High band 802.15.4a-2007 */
788 hw->phy->supported.channels[4] |= 0xffe0;
789 /* 750 MHz O-QPSK 802.15.4c-2009 */
790 hw->phy->supported.channels[5] |= 0xf;
791 /* 750 MHz MPSK 802.15.4c-2009 */
792 hw->phy->supported.channels[5] |= 0xf0;
793 /* 950 MHz BPSK 802.15.4d-2009 */
794 hw->phy->supported.channels[6] |= 0x3ff;
795 /* 950 MHz GFSK 802.15.4d-2009 */
796 hw->phy->supported.channels[6] |= 0x3ffc00;
798 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
800 /* hwsim phy channel 13 as default */
801 hw->phy->current_channel = 13;
802 pib = kzalloc(sizeof(*pib), GFP_KERNEL);
808 rcu_assign_pointer(phy->pib, pib);
810 INIT_LIST_HEAD(&phy->edges);
812 hw->flags = IEEE802154_HW_PROMISCUOUS;
815 err = ieee802154_register_hw(hw);
819 mutex_lock(&hwsim_phys_lock);
821 err = hwsim_subscribe_all_others(phy);
823 mutex_unlock(&hwsim_phys_lock);
827 list_add_tail(&phy->list, &hwsim_phys);
828 mutex_unlock(&hwsim_phys_lock);
830 hwsim_mcast_new_radio(info, phy);
835 ieee802154_unregister_hw(phy->hw);
839 ieee802154_free_hw(phy->hw);
843 static void hwsim_del(struct hwsim_phy *phy)
845 struct hwsim_pib *pib;
846 struct hwsim_edge *e;
848 hwsim_edge_unsubscribe_me(phy);
850 list_del(&phy->list);
853 list_for_each_entry_rcu(e, &phy->edges, list) {
854 list_del_rcu(&e->list);
857 pib = rcu_dereference(phy->pib);
862 ieee802154_unregister_hw(phy->hw);
863 ieee802154_free_hw(phy->hw);
866 static int hwsim_probe(struct platform_device *pdev)
868 struct hwsim_phy *phy, *tmp;
871 for (i = 0; i < 2; i++) {
872 err = hwsim_add_one(NULL, &pdev->dev, true);
877 dev_info(&pdev->dev, "Added 2 mac802154 hwsim hardware radios\n");
881 mutex_lock(&hwsim_phys_lock);
882 list_for_each_entry_safe(phy, tmp, &hwsim_phys, list)
884 mutex_unlock(&hwsim_phys_lock);
888 static int hwsim_remove(struct platform_device *pdev)
890 struct hwsim_phy *phy, *tmp;
892 mutex_lock(&hwsim_phys_lock);
893 list_for_each_entry_safe(phy, tmp, &hwsim_phys, list)
895 mutex_unlock(&hwsim_phys_lock);
900 static struct platform_driver mac802154hwsim_driver = {
901 .probe = hwsim_probe,
902 .remove = hwsim_remove,
904 .name = "mac802154_hwsim",
908 static __init int hwsim_init_module(void)
912 rc = genl_register_family(&hwsim_genl_family);
916 mac802154hwsim_dev = platform_device_register_simple("mac802154_hwsim",
918 if (IS_ERR(mac802154hwsim_dev)) {
919 rc = PTR_ERR(mac802154hwsim_dev);
923 rc = platform_driver_register(&mac802154hwsim_driver);
930 platform_device_unregister(mac802154hwsim_dev);
932 genl_unregister_family(&hwsim_genl_family);
936 static __exit void hwsim_remove_module(void)
938 genl_unregister_family(&hwsim_genl_family);
939 platform_driver_unregister(&mac802154hwsim_driver);
940 platform_device_unregister(mac802154hwsim_dev);
943 module_init(hwsim_init_module);
944 module_exit(hwsim_remove_module);