Loading drivers/ieee802154/fakehard.c +47 −12 Original line number Diff line number Diff line Loading @@ -32,9 +32,29 @@ #include <net/nl802154.h> #include <net/wpan-phy.h> struct wpan_phy *net_to_phy(struct net_device *dev) struct fakehard_priv { struct wpan_phy *phy; }; static struct wpan_phy *fake_to_phy(const struct net_device *dev) { return container_of(dev->dev.parent, struct wpan_phy, dev); struct fakehard_priv *priv = netdev_priv(dev); return priv->phy; } /** * fake_get_phy - Return a phy corresponding to this device. * @dev: The network device for which to return the wan-phy object * * This function returns a wpan-phy object corresponding to the passed * network device. Reference counter for wpan-phy object is incremented, * so when the wpan-phy isn't necessary, you should drop the reference * via @wpan_phy_put() call. */ static struct wpan_phy *fake_get_phy(const struct net_device *dev) { struct wpan_phy *phy = fake_to_phy(dev); return to_phy(get_device(&phy->dev)); } /** Loading @@ -43,7 +63,7 @@ struct wpan_phy *net_to_phy(struct net_device *dev) * * Return the ID of the PAN from the PIB. */ static u16 fake_get_pan_id(struct net_device *dev) static u16 fake_get_pan_id(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -58,7 +78,7 @@ static u16 fake_get_pan_id(struct net_device *dev) * device. If the device has not yet had a short address assigned * then this should return 0xFFFF to indicate a lack of association. */ static u16 fake_get_short_addr(struct net_device *dev) static u16 fake_get_short_addr(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -78,7 +98,7 @@ static u16 fake_get_short_addr(struct net_device *dev) * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 * document. */ static u8 fake_get_dsn(struct net_device *dev) static u8 fake_get_dsn(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -98,7 +118,7 @@ static u8 fake_get_dsn(struct net_device *dev) * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 * document. */ static u8 fake_get_bsn(struct net_device *dev) static u8 fake_get_bsn(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -121,7 +141,7 @@ static u8 fake_get_bsn(struct net_device *dev) static int fake_assoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; Loading Loading @@ -196,7 +216,7 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr, u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, u8 coord_realign) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; Loading Loading @@ -239,6 +259,8 @@ static struct ieee802154_mlme_ops fake_mlme = { .start_req = fake_start_req, .scan_req = fake_scan_req, .get_phy = fake_get_phy, .get_pan_id = fake_get_pan_id, .get_short_addr = fake_get_short_addr, .get_dsn = fake_get_dsn, Loading Loading @@ -313,7 +335,7 @@ static const struct net_device_ops fake_ops = { static void ieee802154_fake_destruct(struct net_device *dev) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); wpan_phy_unregister(phy); free_netdev(dev); Loading @@ -338,13 +360,14 @@ static void ieee802154_fake_setup(struct net_device *dev) static int __devinit ieee802154fake_probe(struct platform_device *pdev) { struct net_device *dev; struct fakehard_priv *priv; struct wpan_phy *phy = wpan_phy_alloc(0); int err; if (!phy) return -ENOMEM; dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d", ieee802154_fake_setup); if (!dev) { wpan_phy_free(phy); return -ENOMEM; Loading @@ -356,12 +379,23 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) dev->addr_len); memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); phy->channels_supported = (1 << 27) - 1; /* * For now we'd like to emulate 2.4 GHz-only device, * both O-QPSK and CSS */ /* 2.4 GHz O-QPSK 802.15.4-2003 */ phy->channels_supported[0] |= 0x7FFF800; /* 2.4 GHz CSS 802.15.4a-2007 */ phy->channels_supported[3] |= 0x3fff; phy->transmit_power = 0xbf; dev->netdev_ops = &fake_ops; dev->ml_priv = &fake_mlme; priv = netdev_priv(dev); priv->phy = phy; /* * If the name is a format string the caller wants us to do a * name allocation. Loading @@ -372,11 +406,12 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) goto out; } wpan_phy_set_dev(phy, &pdev->dev); SET_NETDEV_DEV(dev, &phy->dev); platform_set_drvdata(pdev, dev); err = wpan_phy_register(&pdev->dev, phy); err = wpan_phy_register(phy); if (err) goto out; Loading include/linux/nl802154.h +6 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,9 @@ enum { IEEE802154_ATTR_SEC, IEEE802154_ATTR_PAGE, IEEE802154_ATTR_CHANNEL_PAGE_LIST, IEEE802154_ATTR_PHY_NAME, __IEEE802154_ATTR_MAX, }; Loading Loading @@ -114,6 +117,9 @@ enum { IEEE802154_RX_ENABLE_CONF, /* Not supported yet */ IEEE802154_LIST_IFACE, IEEE802154_LIST_PHY, IEEE802154_ADD_IFACE, IEEE802154_DEL_IFACE, __IEEE802154_CMD_MAX, }; Loading include/net/ieee802154_netdev.h +11 −5 Original line number Diff line number Diff line Loading @@ -74,8 +74,12 @@ static inline int mac_cb_type(struct sk_buff *skb) #define IEEE802154_MAC_SCAN_PASSIVE 2 #define IEEE802154_MAC_SCAN_ORPHAN 3 struct wpan_phy; /* * This should be located at net_device->ml_priv * * get_phy should increment the reference counting on returned phy. * Use wpan_wpy_put to put that reference. */ struct ieee802154_mlme_ops { int (*assoc_req)(struct net_device *dev, Loading @@ -94,18 +98,20 @@ struct ieee802154_mlme_ops { int (*scan_req)(struct net_device *dev, u8 type, u32 channels, u8 page, u8 duration); struct wpan_phy *(*get_phy)(const struct net_device *dev); /* * FIXME: these should become the part of PIB/MIB interface. * However we still don't have IB interface of any kind */ u16 (*get_pan_id)(struct net_device *dev); u16 (*get_short_addr)(struct net_device *dev); u8 (*get_dsn)(struct net_device *dev); u8 (*get_bsn)(struct net_device *dev); u16 (*get_pan_id)(const struct net_device *dev); u16 (*get_short_addr)(const struct net_device *dev); u8 (*get_dsn)(const struct net_device *dev); u8 (*get_bsn)(const struct net_device *dev); }; static inline struct ieee802154_mlme_ops *ieee802154_mlme_ops( struct net_device *dev) const struct net_device *dev) { return dev->ml_priv; } Loading include/net/wpan-phy.h +20 −2 Original line number Diff line number Diff line Loading @@ -34,20 +34,32 @@ struct wpan_phy { */ u8 current_channel; u8 current_page; u32 channels_supported; u32 channels_supported[32]; u8 transmit_power; u8 cca_mode; struct device dev; int idx; struct net_device *(*add_iface)(struct wpan_phy *phy, const char *name); void (*del_iface)(struct wpan_phy *phy, struct net_device *dev); char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); }; #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev) struct wpan_phy *wpan_phy_alloc(size_t priv_size); int wpan_phy_register(struct device *parent, struct wpan_phy *phy); static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev) { phy->dev.parent = dev; } int wpan_phy_register(struct wpan_phy *phy); void wpan_phy_unregister(struct wpan_phy *phy); void wpan_phy_free(struct wpan_phy *phy); /* Same semantics as for class_for_each_device */ int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data); static inline void *wpan_phy_priv(struct wpan_phy *phy) { Loading @@ -56,6 +68,12 @@ static inline void *wpan_phy_priv(struct wpan_phy *phy) } struct wpan_phy *wpan_phy_find(const char *str); static inline void wpan_phy_put(struct wpan_phy *phy) { put_device(&phy->dev); } static inline const char *wpan_phy_name(struct wpan_phy *phy) { return dev_name(&phy->dev); Loading net/ieee802154/Makefile +2 −2 Original line number Diff line number Diff line obj-$(CONFIG_IEEE802154) += nl802154.o af_802154.o wpan-class.o nl802154-y := netlink.o nl_policy.o obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o af_802154-y := af_ieee802154.o raw.o dgram.o ccflags-y += -Wall -DDEBUG Loading
drivers/ieee802154/fakehard.c +47 −12 Original line number Diff line number Diff line Loading @@ -32,9 +32,29 @@ #include <net/nl802154.h> #include <net/wpan-phy.h> struct wpan_phy *net_to_phy(struct net_device *dev) struct fakehard_priv { struct wpan_phy *phy; }; static struct wpan_phy *fake_to_phy(const struct net_device *dev) { return container_of(dev->dev.parent, struct wpan_phy, dev); struct fakehard_priv *priv = netdev_priv(dev); return priv->phy; } /** * fake_get_phy - Return a phy corresponding to this device. * @dev: The network device for which to return the wan-phy object * * This function returns a wpan-phy object corresponding to the passed * network device. Reference counter for wpan-phy object is incremented, * so when the wpan-phy isn't necessary, you should drop the reference * via @wpan_phy_put() call. */ static struct wpan_phy *fake_get_phy(const struct net_device *dev) { struct wpan_phy *phy = fake_to_phy(dev); return to_phy(get_device(&phy->dev)); } /** Loading @@ -43,7 +63,7 @@ struct wpan_phy *net_to_phy(struct net_device *dev) * * Return the ID of the PAN from the PIB. */ static u16 fake_get_pan_id(struct net_device *dev) static u16 fake_get_pan_id(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -58,7 +78,7 @@ static u16 fake_get_pan_id(struct net_device *dev) * device. If the device has not yet had a short address assigned * then this should return 0xFFFF to indicate a lack of association. */ static u16 fake_get_short_addr(struct net_device *dev) static u16 fake_get_short_addr(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -78,7 +98,7 @@ static u16 fake_get_short_addr(struct net_device *dev) * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 * document. */ static u8 fake_get_dsn(struct net_device *dev) static u8 fake_get_dsn(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -98,7 +118,7 @@ static u8 fake_get_dsn(struct net_device *dev) * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 * document. */ static u8 fake_get_bsn(struct net_device *dev) static u8 fake_get_bsn(const struct net_device *dev) { BUG_ON(dev->type != ARPHRD_IEEE802154); Loading @@ -121,7 +141,7 @@ static u8 fake_get_bsn(struct net_device *dev) static int fake_assoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; Loading Loading @@ -196,7 +216,7 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr, u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, u8 coord_realign) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; Loading Loading @@ -239,6 +259,8 @@ static struct ieee802154_mlme_ops fake_mlme = { .start_req = fake_start_req, .scan_req = fake_scan_req, .get_phy = fake_get_phy, .get_pan_id = fake_get_pan_id, .get_short_addr = fake_get_short_addr, .get_dsn = fake_get_dsn, Loading Loading @@ -313,7 +335,7 @@ static const struct net_device_ops fake_ops = { static void ieee802154_fake_destruct(struct net_device *dev) { struct wpan_phy *phy = net_to_phy(dev); struct wpan_phy *phy = fake_to_phy(dev); wpan_phy_unregister(phy); free_netdev(dev); Loading @@ -338,13 +360,14 @@ static void ieee802154_fake_setup(struct net_device *dev) static int __devinit ieee802154fake_probe(struct platform_device *pdev) { struct net_device *dev; struct fakehard_priv *priv; struct wpan_phy *phy = wpan_phy_alloc(0); int err; if (!phy) return -ENOMEM; dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d", ieee802154_fake_setup); if (!dev) { wpan_phy_free(phy); return -ENOMEM; Loading @@ -356,12 +379,23 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) dev->addr_len); memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); phy->channels_supported = (1 << 27) - 1; /* * For now we'd like to emulate 2.4 GHz-only device, * both O-QPSK and CSS */ /* 2.4 GHz O-QPSK 802.15.4-2003 */ phy->channels_supported[0] |= 0x7FFF800; /* 2.4 GHz CSS 802.15.4a-2007 */ phy->channels_supported[3] |= 0x3fff; phy->transmit_power = 0xbf; dev->netdev_ops = &fake_ops; dev->ml_priv = &fake_mlme; priv = netdev_priv(dev); priv->phy = phy; /* * If the name is a format string the caller wants us to do a * name allocation. Loading @@ -372,11 +406,12 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) goto out; } wpan_phy_set_dev(phy, &pdev->dev); SET_NETDEV_DEV(dev, &phy->dev); platform_set_drvdata(pdev, dev); err = wpan_phy_register(&pdev->dev, phy); err = wpan_phy_register(phy); if (err) goto out; Loading
include/linux/nl802154.h +6 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,9 @@ enum { IEEE802154_ATTR_SEC, IEEE802154_ATTR_PAGE, IEEE802154_ATTR_CHANNEL_PAGE_LIST, IEEE802154_ATTR_PHY_NAME, __IEEE802154_ATTR_MAX, }; Loading Loading @@ -114,6 +117,9 @@ enum { IEEE802154_RX_ENABLE_CONF, /* Not supported yet */ IEEE802154_LIST_IFACE, IEEE802154_LIST_PHY, IEEE802154_ADD_IFACE, IEEE802154_DEL_IFACE, __IEEE802154_CMD_MAX, }; Loading
include/net/ieee802154_netdev.h +11 −5 Original line number Diff line number Diff line Loading @@ -74,8 +74,12 @@ static inline int mac_cb_type(struct sk_buff *skb) #define IEEE802154_MAC_SCAN_PASSIVE 2 #define IEEE802154_MAC_SCAN_ORPHAN 3 struct wpan_phy; /* * This should be located at net_device->ml_priv * * get_phy should increment the reference counting on returned phy. * Use wpan_wpy_put to put that reference. */ struct ieee802154_mlme_ops { int (*assoc_req)(struct net_device *dev, Loading @@ -94,18 +98,20 @@ struct ieee802154_mlme_ops { int (*scan_req)(struct net_device *dev, u8 type, u32 channels, u8 page, u8 duration); struct wpan_phy *(*get_phy)(const struct net_device *dev); /* * FIXME: these should become the part of PIB/MIB interface. * However we still don't have IB interface of any kind */ u16 (*get_pan_id)(struct net_device *dev); u16 (*get_short_addr)(struct net_device *dev); u8 (*get_dsn)(struct net_device *dev); u8 (*get_bsn)(struct net_device *dev); u16 (*get_pan_id)(const struct net_device *dev); u16 (*get_short_addr)(const struct net_device *dev); u8 (*get_dsn)(const struct net_device *dev); u8 (*get_bsn)(const struct net_device *dev); }; static inline struct ieee802154_mlme_ops *ieee802154_mlme_ops( struct net_device *dev) const struct net_device *dev) { return dev->ml_priv; } Loading
include/net/wpan-phy.h +20 −2 Original line number Diff line number Diff line Loading @@ -34,20 +34,32 @@ struct wpan_phy { */ u8 current_channel; u8 current_page; u32 channels_supported; u32 channels_supported[32]; u8 transmit_power; u8 cca_mode; struct device dev; int idx; struct net_device *(*add_iface)(struct wpan_phy *phy, const char *name); void (*del_iface)(struct wpan_phy *phy, struct net_device *dev); char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); }; #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev) struct wpan_phy *wpan_phy_alloc(size_t priv_size); int wpan_phy_register(struct device *parent, struct wpan_phy *phy); static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev) { phy->dev.parent = dev; } int wpan_phy_register(struct wpan_phy *phy); void wpan_phy_unregister(struct wpan_phy *phy); void wpan_phy_free(struct wpan_phy *phy); /* Same semantics as for class_for_each_device */ int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data); static inline void *wpan_phy_priv(struct wpan_phy *phy) { Loading @@ -56,6 +68,12 @@ static inline void *wpan_phy_priv(struct wpan_phy *phy) } struct wpan_phy *wpan_phy_find(const char *str); static inline void wpan_phy_put(struct wpan_phy *phy) { put_device(&phy->dev); } static inline const char *wpan_phy_name(struct wpan_phy *phy) { return dev_name(&phy->dev); Loading
net/ieee802154/Makefile +2 −2 Original line number Diff line number Diff line obj-$(CONFIG_IEEE802154) += nl802154.o af_802154.o wpan-class.o nl802154-y := netlink.o nl_policy.o obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o af_802154-y := af_ieee802154.o raw.o dgram.o ccflags-y += -Wall -DDEBUG