xref: /OK3568_Linux_fs/kernel/net/wimax/op-state-get.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Linux WiMAX
4*4882a593Smuzhiyun  * Implement and export a method for getting a WiMAX device current state
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Based on previous WiMAX core work by:
9*4882a593Smuzhiyun  *  Copyright (C) 2008 Intel Corporation <linux-wimax@intel.com>
10*4882a593Smuzhiyun  *  Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <net/wimax.h>
14*4882a593Smuzhiyun #include <net/genetlink.h>
15*4882a593Smuzhiyun #include <linux/wimax.h>
16*4882a593Smuzhiyun #include <linux/security.h>
17*4882a593Smuzhiyun #include "wimax-internal.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define D_SUBMODULE op_state_get
20*4882a593Smuzhiyun #include "debug-levels.h"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun  * Exporting to user space over generic netlink
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * Parse the state get command from user space, return a combination
27*4882a593Smuzhiyun  * value that describe the current state.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * No attributes.
30*4882a593Smuzhiyun  */
wimax_gnl_doit_state_get(struct sk_buff * skb,struct genl_info * info)31*4882a593Smuzhiyun int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	int result, ifindex;
34*4882a593Smuzhiyun 	struct wimax_dev *wimax_dev;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info);
37*4882a593Smuzhiyun 	result = -ENODEV;
38*4882a593Smuzhiyun 	if (info->attrs[WIMAX_GNL_STGET_IFIDX] == NULL) {
39*4882a593Smuzhiyun 		pr_err("WIMAX_GNL_OP_STATE_GET: can't find IFIDX attribute\n");
40*4882a593Smuzhiyun 		goto error_no_wimax_dev;
41*4882a593Smuzhiyun 	}
42*4882a593Smuzhiyun 	ifindex = nla_get_u32(info->attrs[WIMAX_GNL_STGET_IFIDX]);
43*4882a593Smuzhiyun 	wimax_dev = wimax_dev_get_by_genl_info(info, ifindex);
44*4882a593Smuzhiyun 	if (wimax_dev == NULL)
45*4882a593Smuzhiyun 		goto error_no_wimax_dev;
46*4882a593Smuzhiyun 	/* Execute the operation and send the result back to user space */
47*4882a593Smuzhiyun 	result = wimax_state_get(wimax_dev);
48*4882a593Smuzhiyun 	dev_put(wimax_dev->net_dev);
49*4882a593Smuzhiyun error_no_wimax_dev:
50*4882a593Smuzhiyun 	d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
51*4882a593Smuzhiyun 	return result;
52*4882a593Smuzhiyun }
53