Paulius Zaleckas | 7f0333e | 2009-05-13 06:20:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux WiMAX |
| 3 | * Implement and export a method for getting a WiMAX device current state |
| 4 | * |
| 5 | * Copyright (C) 2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt> |
| 6 | * |
| 7 | * Based on previous WiMAX core work by: |
| 8 | * Copyright (C) 2008 Intel Corporation <linux-wimax@intel.com> |
| 9 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License version |
| 13 | * 2 as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 23 | * 02110-1301, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <net/wimax.h> |
| 27 | #include <net/genetlink.h> |
| 28 | #include <linux/wimax.h> |
| 29 | #include <linux/security.h> |
| 30 | #include "wimax-internal.h" |
| 31 | |
| 32 | #define D_SUBMODULE op_state_get |
| 33 | #include "debug-levels.h" |
| 34 | |
| 35 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 36 | static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = { |
Paulius Zaleckas | 7f0333e | 2009-05-13 06:20:29 -0700 | [diff] [blame] | 37 | [WIMAX_GNL_STGET_IFIDX] = { |
| 38 | .type = NLA_U32, |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | /* |
| 44 | * Exporting to user space over generic netlink |
| 45 | * |
| 46 | * Parse the state get command from user space, return a combination |
| 47 | * value that describe the current state. |
| 48 | * |
| 49 | * No attributes. |
| 50 | */ |
| 51 | static |
| 52 | int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info) |
| 53 | { |
| 54 | int result, ifindex; |
| 55 | struct wimax_dev *wimax_dev; |
Paulius Zaleckas | 7f0333e | 2009-05-13 06:20:29 -0700 | [diff] [blame] | 56 | |
| 57 | d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); |
| 58 | result = -ENODEV; |
| 59 | if (info->attrs[WIMAX_GNL_STGET_IFIDX] == NULL) { |
| 60 | printk(KERN_ERR "WIMAX_GNL_OP_STATE_GET: can't find IFIDX " |
| 61 | "attribute\n"); |
| 62 | goto error_no_wimax_dev; |
| 63 | } |
| 64 | ifindex = nla_get_u32(info->attrs[WIMAX_GNL_STGET_IFIDX]); |
| 65 | wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); |
| 66 | if (wimax_dev == NULL) |
| 67 | goto error_no_wimax_dev; |
Paulius Zaleckas | 7f0333e | 2009-05-13 06:20:29 -0700 | [diff] [blame] | 68 | /* Execute the operation and send the result back to user space */ |
| 69 | result = wimax_state_get(wimax_dev); |
| 70 | dev_put(wimax_dev->net_dev); |
| 71 | error_no_wimax_dev: |
| 72 | d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | struct genl_ops wimax_gnl_state_get = { |
| 78 | .cmd = WIMAX_GNL_OP_STATE_GET, |
| 79 | .flags = GENL_ADMIN_PERM, |
| 80 | .policy = wimax_gnl_state_get_policy, |
| 81 | .doit = wimax_gnl_doit_state_get, |
| 82 | .dumpit = NULL, |
| 83 | }; |