nl802154.c (946e0f6ffcaa614012d646f4cf84efdd62628c8b) nl802154.c (66e5c2672cd11b9310008099faf6a4ffb9dfb6d0)
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.

--- 66 unchanged lines hidden (view full) ---

75 if (have_wpan_dev_id) {
76 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
77 wpan_phy_idx = wpan_dev_id >> 32;
78 }
79
80 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
81 struct wpan_dev *wpan_dev;
82
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.

--- 66 unchanged lines hidden (view full) ---

75 if (have_wpan_dev_id) {
76 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
77 wpan_phy_idx = wpan_dev_id >> 32;
78 }
79
80 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
81 struct wpan_dev *wpan_dev;
82
83 /* TODO netns compare */
83 if (wpan_phy_net(&rdev->wpan_phy) != netns)
84 continue;
84
85 if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
86 continue;
87
88 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
89 if (have_ifidx && wpan_dev->netdev &&
90 wpan_dev->netdev->ifindex == ifidx) {
91 result = wpan_dev;

--- 78 unchanged lines hidden (view full) ---

170
171 rdev = tmp;
172 }
173 }
174
175 if (!rdev)
176 return ERR_PTR(-ENODEV);
177
85
86 if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
87 continue;
88
89 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
90 if (have_ifidx && wpan_dev->netdev &&
91 wpan_dev->netdev->ifindex == ifidx) {
92 result = wpan_dev;

--- 78 unchanged lines hidden (view full) ---

171
172 rdev = tmp;
173 }
174 }
175
176 if (!rdev)
177 return ERR_PTR(-ENODEV);
178
178 /* TODO netns compare */
179 if (netns != wpan_phy_net(&rdev->wpan_phy))
180 return ERR_PTR(-ENODEV);
179
180 return rdev;
181}
182
183/* This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 *
186 * The result of this can be a PTR_ERR and hence must

--- 41 unchanged lines hidden (view full) ---

228 [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
229
230 [NL802154_ATTR_WPAN_PHY_CAPS] = { .type = NLA_NESTED },
231
232 [NL802154_ATTR_SUPPORTED_COMMANDS] = { .type = NLA_NESTED },
233
234 [NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
235
181
182 return rdev;
183}
184
185/* This function returns a pointer to the driver
186 * that the genl_info item that is passed refers to.
187 *
188 * The result of this can be a PTR_ERR and hence must

--- 41 unchanged lines hidden (view full) ---

230 [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
231
232 [NL802154_ATTR_WPAN_PHY_CAPS] = { .type = NLA_NESTED },
233
234 [NL802154_ATTR_SUPPORTED_COMMANDS] = { .type = NLA_NESTED },
235
236 [NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
237
238 [NL802154_ATTR_PID] = { .type = NLA_U32 },
239 [NL802154_ATTR_NETNS_FD] = { .type = NLA_U32 },
236#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
237 [NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
238 [NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
239 [NL802154_ATTR_SEC_OUT_KEY_ID] = { .type = NLA_NESTED, },
240 [NL802154_ATTR_SEC_FRAME_COUNTER] = { .type = NLA_U32 },
241
242 [NL802154_ATTR_SEC_LEVEL] = { .type = NLA_NESTED },
243 [NL802154_ATTR_SEC_DEVICE] = { .type = NLA_NESTED },

--- 341 unchanged lines hidden (view full) ---

585 state->filter_wpan_phy = nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]);
586 if (tb[NL802154_ATTR_WPAN_DEV])
587 state->filter_wpan_phy = nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]) >> 32;
588 if (tb[NL802154_ATTR_IFINDEX]) {
589 struct net_device *netdev;
590 struct cfg802154_registered_device *rdev;
591 int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
592
240#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
241 [NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
242 [NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
243 [NL802154_ATTR_SEC_OUT_KEY_ID] = { .type = NLA_NESTED, },
244 [NL802154_ATTR_SEC_FRAME_COUNTER] = { .type = NLA_U32 },
245
246 [NL802154_ATTR_SEC_LEVEL] = { .type = NLA_NESTED },
247 [NL802154_ATTR_SEC_DEVICE] = { .type = NLA_NESTED },

--- 341 unchanged lines hidden (view full) ---

589 state->filter_wpan_phy = nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]);
590 if (tb[NL802154_ATTR_WPAN_DEV])
591 state->filter_wpan_phy = nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]) >> 32;
592 if (tb[NL802154_ATTR_IFINDEX]) {
593 struct net_device *netdev;
594 struct cfg802154_registered_device *rdev;
595 int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
596
593 /* TODO netns */
594 netdev = __dev_get_by_index(&init_net, ifidx);
595 if (!netdev)
596 return -ENODEV;
597 if (netdev->ieee802154_ptr) {
598 rdev = wpan_phy_to_rdev(
599 netdev->ieee802154_ptr->wpan_phy);
600 state->filter_wpan_phy = rdev->wpan_phy_idx;
601 }

--- 22 unchanged lines hidden (view full) ---

624 kfree(state);
625 rtnl_unlock();
626 return ret;
627 }
628 cb->args[0] = (long)state;
629 }
630
631 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
597 netdev = __dev_get_by_index(&init_net, ifidx);
598 if (!netdev)
599 return -ENODEV;
600 if (netdev->ieee802154_ptr) {
601 rdev = wpan_phy_to_rdev(
602 netdev->ieee802154_ptr->wpan_phy);
603 state->filter_wpan_phy = rdev->wpan_phy_idx;
604 }

--- 22 unchanged lines hidden (view full) ---

627 kfree(state);
628 rtnl_unlock();
629 return ret;
630 }
631 cb->args[0] = (long)state;
632 }
633
634 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
632 /* TODO net ns compare */
635 if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
636 continue;
633 if (++idx <= state->start)
634 continue;
635 if (state->filter_wpan_phy != -1 &&
636 state->filter_wpan_phy != rdev->wpan_phy_idx)
637 continue;
638 /* attempt to fit multiple wpan_phy data chunks into the skb */
639 ret = nl802154_send_wpan_phy(rdev,
640 NL802154_CMD_NEW_WPAN_PHY,

--- 225 unchanged lines hidden (view full) ---

866 int if_idx = 0;
867 int wp_start = cb->args[0];
868 int if_start = cb->args[1];
869 struct cfg802154_registered_device *rdev;
870 struct wpan_dev *wpan_dev;
871
872 rtnl_lock();
873 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
637 if (++idx <= state->start)
638 continue;
639 if (state->filter_wpan_phy != -1 &&
640 state->filter_wpan_phy != rdev->wpan_phy_idx)
641 continue;
642 /* attempt to fit multiple wpan_phy data chunks into the skb */
643 ret = nl802154_send_wpan_phy(rdev,
644 NL802154_CMD_NEW_WPAN_PHY,

--- 225 unchanged lines hidden (view full) ---

870 int if_idx = 0;
871 int wp_start = cb->args[0];
872 int if_start = cb->args[1];
873 struct cfg802154_registered_device *rdev;
874 struct wpan_dev *wpan_dev;
875
876 rtnl_lock();
877 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
874 /* TODO netns compare */
878 if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
879 continue;
875 if (wp_idx < wp_start) {
876 wp_idx++;
877 continue;
878 }
879 if_idx = 0;
880
881 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
882 if (if_idx < if_start) {

--- 383 unchanged lines hidden (view full) ---

1266 ackreq = nla_get_u8(info->attrs[NL802154_ATTR_ACKREQ_DEFAULT]);
1267
1268 if (ackreq != 0 && ackreq != 1)
1269 return -EINVAL;
1270
1271 return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
1272}
1273
880 if (wp_idx < wp_start) {
881 wp_idx++;
882 continue;
883 }
884 if_idx = 0;
885
886 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
887 if (if_idx < if_start) {

--- 383 unchanged lines hidden (view full) ---

1271 ackreq = nla_get_u8(info->attrs[NL802154_ATTR_ACKREQ_DEFAULT]);
1272
1273 if (ackreq != 0 && ackreq != 1)
1274 return -EINVAL;
1275
1276 return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
1277}
1278
1279static int nl802154_wpan_phy_netns(struct sk_buff *skb, struct genl_info *info)
1280{
1281 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1282 struct net *net;
1283 int err;
1284
1285 if (info->attrs[NL802154_ATTR_PID]) {
1286 u32 pid = nla_get_u32(info->attrs[NL802154_ATTR_PID]);
1287
1288 net = get_net_ns_by_pid(pid);
1289 } else if (info->attrs[NL802154_ATTR_NETNS_FD]) {
1290 u32 fd = nla_get_u32(info->attrs[NL802154_ATTR_NETNS_FD]);
1291
1292 net = get_net_ns_by_fd(fd);
1293 } else {
1294 return -EINVAL;
1295 }
1296
1297 if (IS_ERR(net))
1298 return PTR_ERR(net);
1299
1300 err = 0;
1301
1302 /* check if anything to do */
1303 if (!net_eq(wpan_phy_net(&rdev->wpan_phy), net))
1304 err = cfg802154_switch_netns(rdev, net);
1305
1306 put_net(net);
1307 return err;
1308}
1309
1274#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
1275static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
1276 [NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },
1277 [NL802154_DEV_ADDR_ATTR_MODE] = { .type = NLA_U32 },
1278 [NL802154_DEV_ADDR_ATTR_SHORT] = { .type = NLA_U16 },
1279 [NL802154_DEV_ADDR_ATTR_EXTENDED] = { .type = NLA_U64 },
1280};
1281

--- 975 unchanged lines hidden (view full) ---

2257 .cmd = NL802154_CMD_SET_TX_POWER,
2258 .doit = nl802154_set_tx_power,
2259 .policy = nl802154_policy,
2260 .flags = GENL_ADMIN_PERM,
2261 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2262 NL802154_FLAG_NEED_RTNL,
2263 },
2264 {
1310#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
1311static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
1312 [NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },
1313 [NL802154_DEV_ADDR_ATTR_MODE] = { .type = NLA_U32 },
1314 [NL802154_DEV_ADDR_ATTR_SHORT] = { .type = NLA_U16 },
1315 [NL802154_DEV_ADDR_ATTR_EXTENDED] = { .type = NLA_U64 },
1316};
1317

--- 975 unchanged lines hidden (view full) ---

2293 .cmd = NL802154_CMD_SET_TX_POWER,
2294 .doit = nl802154_set_tx_power,
2295 .policy = nl802154_policy,
2296 .flags = GENL_ADMIN_PERM,
2297 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2298 NL802154_FLAG_NEED_RTNL,
2299 },
2300 {
2301 .cmd = NL802154_CMD_SET_WPAN_PHY_NETNS,
2302 .doit = nl802154_wpan_phy_netns,
2303 .policy = nl802154_policy,
2304 .flags = GENL_ADMIN_PERM,
2305 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2306 NL802154_FLAG_NEED_RTNL,
2307 },
2308 {
2265 .cmd = NL802154_CMD_SET_PAN_ID,
2266 .doit = nl802154_set_pan_id,
2267 .policy = nl802154_policy,
2268 .flags = GENL_ADMIN_PERM,
2269 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2270 NL802154_FLAG_NEED_RTNL,
2271 },
2272 {

--- 173 unchanged lines hidden ---
2309 .cmd = NL802154_CMD_SET_PAN_ID,
2310 .doit = nl802154_set_pan_id,
2311 .policy = nl802154_policy,
2312 .flags = GENL_ADMIN_PERM,
2313 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2314 NL802154_FLAG_NEED_RTNL,
2315 },
2316 {

--- 173 unchanged lines hidden ---