1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Linux WiMAX
4*4882a593Smuzhiyun * Generic messaging interface between userspace and driver/device
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
7*4882a593Smuzhiyun * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This implements a direct communication channel between user space and
10*4882a593Smuzhiyun * the driver/device, by which free form messages can be sent back and
11*4882a593Smuzhiyun * forth.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This is intended for device-specific features, vendor quirks, etc.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * See include/net/wimax.h
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * GENERIC NETLINK ENCODING AND CAPACITY
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * A destination "pipe name" is added to each message; it is up to the
20*4882a593Smuzhiyun * drivers to assign or use those names (if using them at all).
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Messages are encoded as a binary netlink attribute using nla_put()
23*4882a593Smuzhiyun * using type NLA_UNSPEC (as some versions of libnl still in
24*4882a593Smuzhiyun * deployment don't yet understand NLA_BINARY).
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * The maximum capacity of this transport is PAGESIZE per message (so
27*4882a593Smuzhiyun * the actual payload will be bit smaller depending on the
28*4882a593Smuzhiyun * netlink/generic netlink attributes and headers).
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * RECEPTION OF MESSAGES
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * When a message is received from user space, it is passed verbatim
33*4882a593Smuzhiyun * to the driver calling wimax_dev->op_msg_from_user(). The return
34*4882a593Smuzhiyun * value from this function is passed back to user space as an ack
35*4882a593Smuzhiyun * over the generic netlink protocol.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * The stack doesn't do any processing or interpretation of these
38*4882a593Smuzhiyun * messages.
39*4882a593Smuzhiyun *
40*4882a593Smuzhiyun * SENDING MESSAGES
41*4882a593Smuzhiyun *
42*4882a593Smuzhiyun * Messages can be sent with wimax_msg().
43*4882a593Smuzhiyun *
44*4882a593Smuzhiyun * If the message delivery needs to happen on a different context to
45*4882a593Smuzhiyun * that of its creation, wimax_msg_alloc() can be used to get a
46*4882a593Smuzhiyun * pointer to the message that can be delivered later on with
47*4882a593Smuzhiyun * wimax_msg_send().
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * ROADMAP
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * wimax_gnl_doit_msg_from_user() Process a message from user space
52*4882a593Smuzhiyun * wimax_dev_get_by_genl_info()
53*4882a593Smuzhiyun * wimax_dev->op_msg_from_user() Delivery of message to the driver
54*4882a593Smuzhiyun *
55*4882a593Smuzhiyun * wimax_msg() Send a message to user space
56*4882a593Smuzhiyun * wimax_msg_alloc()
57*4882a593Smuzhiyun * wimax_msg_send()
58*4882a593Smuzhiyun */
59*4882a593Smuzhiyun #include <linux/device.h>
60*4882a593Smuzhiyun #include <linux/slab.h>
61*4882a593Smuzhiyun #include <net/genetlink.h>
62*4882a593Smuzhiyun #include <linux/netdevice.h>
63*4882a593Smuzhiyun #include <linux/wimax.h>
64*4882a593Smuzhiyun #include <linux/security.h>
65*4882a593Smuzhiyun #include <linux/export.h>
66*4882a593Smuzhiyun #include "wimax-internal.h"
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define D_SUBMODULE op_msg
70*4882a593Smuzhiyun #include "debug-levels.h"
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /**
74*4882a593Smuzhiyun * wimax_msg_alloc - Create a new skb for sending a message to userspace
75*4882a593Smuzhiyun *
76*4882a593Smuzhiyun * @wimax_dev: WiMAX device descriptor
77*4882a593Smuzhiyun * @pipe_name: "named pipe" the message will be sent to
78*4882a593Smuzhiyun * @msg: pointer to the message data to send
79*4882a593Smuzhiyun * @size: size of the message to send (in bytes), including the header.
80*4882a593Smuzhiyun * @gfp_flags: flags for memory allocation.
81*4882a593Smuzhiyun *
82*4882a593Smuzhiyun * Returns: %0 if ok, negative errno code on error
83*4882a593Smuzhiyun *
84*4882a593Smuzhiyun * Description:
85*4882a593Smuzhiyun *
86*4882a593Smuzhiyun * Allocates an skb that will contain the message to send to user
87*4882a593Smuzhiyun * space over the messaging pipe and initializes it, copying the
88*4882a593Smuzhiyun * payload.
89*4882a593Smuzhiyun *
90*4882a593Smuzhiyun * Once this call is done, you can deliver it with
91*4882a593Smuzhiyun * wimax_msg_send().
92*4882a593Smuzhiyun *
93*4882a593Smuzhiyun * IMPORTANT:
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * Don't use skb_push()/skb_pull()/skb_reserve() on the skb, as
96*4882a593Smuzhiyun * wimax_msg_send() depends on skb->data being placed at the
97*4882a593Smuzhiyun * beginning of the user message.
98*4882a593Smuzhiyun *
99*4882a593Smuzhiyun * Unlike other WiMAX stack calls, this call can be used way early,
100*4882a593Smuzhiyun * even before wimax_dev_add() is called, as long as the
101*4882a593Smuzhiyun * wimax_dev->net_dev pointer is set to point to a proper
102*4882a593Smuzhiyun * net_dev. This is so that drivers can use it early in case they need
103*4882a593Smuzhiyun * to send stuff around or communicate with user space.
104*4882a593Smuzhiyun */
wimax_msg_alloc(struct wimax_dev * wimax_dev,const char * pipe_name,const void * msg,size_t size,gfp_t gfp_flags)105*4882a593Smuzhiyun struct sk_buff *wimax_msg_alloc(struct wimax_dev *wimax_dev,
106*4882a593Smuzhiyun const char *pipe_name,
107*4882a593Smuzhiyun const void *msg, size_t size,
108*4882a593Smuzhiyun gfp_t gfp_flags)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun int result;
111*4882a593Smuzhiyun struct device *dev = wimax_dev_to_dev(wimax_dev);
112*4882a593Smuzhiyun size_t msg_size;
113*4882a593Smuzhiyun void *genl_msg;
114*4882a593Smuzhiyun struct sk_buff *skb;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun msg_size = nla_total_size(size)
117*4882a593Smuzhiyun + nla_total_size(sizeof(u32))
118*4882a593Smuzhiyun + (pipe_name ? nla_total_size(strlen(pipe_name)) : 0);
119*4882a593Smuzhiyun result = -ENOMEM;
120*4882a593Smuzhiyun skb = genlmsg_new(msg_size, gfp_flags);
121*4882a593Smuzhiyun if (skb == NULL)
122*4882a593Smuzhiyun goto error_new;
123*4882a593Smuzhiyun genl_msg = genlmsg_put(skb, 0, 0, &wimax_gnl_family,
124*4882a593Smuzhiyun 0, WIMAX_GNL_OP_MSG_TO_USER);
125*4882a593Smuzhiyun if (genl_msg == NULL) {
126*4882a593Smuzhiyun dev_err(dev, "no memory to create generic netlink message\n");
127*4882a593Smuzhiyun goto error_genlmsg_put;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun result = nla_put_u32(skb, WIMAX_GNL_MSG_IFIDX,
130*4882a593Smuzhiyun wimax_dev->net_dev->ifindex);
131*4882a593Smuzhiyun if (result < 0) {
132*4882a593Smuzhiyun dev_err(dev, "no memory to add ifindex attribute\n");
133*4882a593Smuzhiyun goto error_nla_put;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun if (pipe_name) {
136*4882a593Smuzhiyun result = nla_put_string(skb, WIMAX_GNL_MSG_PIPE_NAME,
137*4882a593Smuzhiyun pipe_name);
138*4882a593Smuzhiyun if (result < 0) {
139*4882a593Smuzhiyun dev_err(dev, "no memory to add pipe_name attribute\n");
140*4882a593Smuzhiyun goto error_nla_put;
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun result = nla_put(skb, WIMAX_GNL_MSG_DATA, size, msg);
144*4882a593Smuzhiyun if (result < 0) {
145*4882a593Smuzhiyun dev_err(dev, "no memory to add payload (msg %p size %zu) in "
146*4882a593Smuzhiyun "attribute: %d\n", msg, size, result);
147*4882a593Smuzhiyun goto error_nla_put;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun genlmsg_end(skb, genl_msg);
150*4882a593Smuzhiyun return skb;
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun error_nla_put:
153*4882a593Smuzhiyun error_genlmsg_put:
154*4882a593Smuzhiyun error_new:
155*4882a593Smuzhiyun nlmsg_free(skb);
156*4882a593Smuzhiyun return ERR_PTR(result);
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg_alloc);
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /**
162*4882a593Smuzhiyun * wimax_msg_data_len - Return a pointer and size of a message's payload
163*4882a593Smuzhiyun *
164*4882a593Smuzhiyun * @msg: Pointer to a message created with wimax_msg_alloc()
165*4882a593Smuzhiyun * @size: Pointer to where to store the message's size
166*4882a593Smuzhiyun *
167*4882a593Smuzhiyun * Returns the pointer to the message data.
168*4882a593Smuzhiyun */
wimax_msg_data_len(struct sk_buff * msg,size_t * size)169*4882a593Smuzhiyun const void *wimax_msg_data_len(struct sk_buff *msg, size_t *size)
170*4882a593Smuzhiyun {
171*4882a593Smuzhiyun struct nlmsghdr *nlh = (void *) msg->head;
172*4882a593Smuzhiyun struct nlattr *nla;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun nla = nlmsg_find_attr(nlh, sizeof(struct genlmsghdr),
175*4882a593Smuzhiyun WIMAX_GNL_MSG_DATA);
176*4882a593Smuzhiyun if (nla == NULL) {
177*4882a593Smuzhiyun pr_err("Cannot find attribute WIMAX_GNL_MSG_DATA\n");
178*4882a593Smuzhiyun return NULL;
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun *size = nla_len(nla);
181*4882a593Smuzhiyun return nla_data(nla);
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg_data_len);
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun /**
187*4882a593Smuzhiyun * wimax_msg_data - Return a pointer to a message's payload
188*4882a593Smuzhiyun *
189*4882a593Smuzhiyun * @msg: Pointer to a message created with wimax_msg_alloc()
190*4882a593Smuzhiyun */
wimax_msg_data(struct sk_buff * msg)191*4882a593Smuzhiyun const void *wimax_msg_data(struct sk_buff *msg)
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun struct nlmsghdr *nlh = (void *) msg->head;
194*4882a593Smuzhiyun struct nlattr *nla;
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun nla = nlmsg_find_attr(nlh, sizeof(struct genlmsghdr),
197*4882a593Smuzhiyun WIMAX_GNL_MSG_DATA);
198*4882a593Smuzhiyun if (nla == NULL) {
199*4882a593Smuzhiyun pr_err("Cannot find attribute WIMAX_GNL_MSG_DATA\n");
200*4882a593Smuzhiyun return NULL;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun return nla_data(nla);
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg_data);
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun * wimax_msg_len - Return a message's payload length
209*4882a593Smuzhiyun *
210*4882a593Smuzhiyun * @msg: Pointer to a message created with wimax_msg_alloc()
211*4882a593Smuzhiyun */
wimax_msg_len(struct sk_buff * msg)212*4882a593Smuzhiyun ssize_t wimax_msg_len(struct sk_buff *msg)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun struct nlmsghdr *nlh = (void *) msg->head;
215*4882a593Smuzhiyun struct nlattr *nla;
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun nla = nlmsg_find_attr(nlh, sizeof(struct genlmsghdr),
218*4882a593Smuzhiyun WIMAX_GNL_MSG_DATA);
219*4882a593Smuzhiyun if (nla == NULL) {
220*4882a593Smuzhiyun pr_err("Cannot find attribute WIMAX_GNL_MSG_DATA\n");
221*4882a593Smuzhiyun return -EINVAL;
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun return nla_len(nla);
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg_len);
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /**
229*4882a593Smuzhiyun * wimax_msg_send - Send a pre-allocated message to user space
230*4882a593Smuzhiyun *
231*4882a593Smuzhiyun * @wimax_dev: WiMAX device descriptor
232*4882a593Smuzhiyun *
233*4882a593Smuzhiyun * @skb: &struct sk_buff returned by wimax_msg_alloc(). Note the
234*4882a593Smuzhiyun * ownership of @skb is transferred to this function.
235*4882a593Smuzhiyun *
236*4882a593Smuzhiyun * Returns: 0 if ok, < 0 errno code on error
237*4882a593Smuzhiyun *
238*4882a593Smuzhiyun * Description:
239*4882a593Smuzhiyun *
240*4882a593Smuzhiyun * Sends a free-form message that was preallocated with
241*4882a593Smuzhiyun * wimax_msg_alloc() and filled up.
242*4882a593Smuzhiyun *
243*4882a593Smuzhiyun * Assumes that once you pass an skb to this function for sending, it
244*4882a593Smuzhiyun * owns it and will release it when done (on success).
245*4882a593Smuzhiyun *
246*4882a593Smuzhiyun * IMPORTANT:
247*4882a593Smuzhiyun *
248*4882a593Smuzhiyun * Don't use skb_push()/skb_pull()/skb_reserve() on the skb, as
249*4882a593Smuzhiyun * wimax_msg_send() depends on skb->data being placed at the
250*4882a593Smuzhiyun * beginning of the user message.
251*4882a593Smuzhiyun *
252*4882a593Smuzhiyun * Unlike other WiMAX stack calls, this call can be used way early,
253*4882a593Smuzhiyun * even before wimax_dev_add() is called, as long as the
254*4882a593Smuzhiyun * wimax_dev->net_dev pointer is set to point to a proper
255*4882a593Smuzhiyun * net_dev. This is so that drivers can use it early in case they need
256*4882a593Smuzhiyun * to send stuff around or communicate with user space.
257*4882a593Smuzhiyun */
wimax_msg_send(struct wimax_dev * wimax_dev,struct sk_buff * skb)258*4882a593Smuzhiyun int wimax_msg_send(struct wimax_dev *wimax_dev, struct sk_buff *skb)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun struct device *dev = wimax_dev_to_dev(wimax_dev);
261*4882a593Smuzhiyun void *msg = skb->data;
262*4882a593Smuzhiyun size_t size = skb->len;
263*4882a593Smuzhiyun might_sleep();
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun d_printf(1, dev, "CTX: wimax msg, %zu bytes\n", size);
266*4882a593Smuzhiyun d_dump(2, dev, msg, size);
267*4882a593Smuzhiyun genlmsg_multicast(&wimax_gnl_family, skb, 0, 0, GFP_KERNEL);
268*4882a593Smuzhiyun d_printf(1, dev, "CTX: genl multicast done\n");
269*4882a593Smuzhiyun return 0;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg_send);
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun /**
275*4882a593Smuzhiyun * wimax_msg - Send a message to user space
276*4882a593Smuzhiyun *
277*4882a593Smuzhiyun * @wimax_dev: WiMAX device descriptor (properly referenced)
278*4882a593Smuzhiyun * @pipe_name: "named pipe" the message will be sent to
279*4882a593Smuzhiyun * @buf: pointer to the message to send.
280*4882a593Smuzhiyun * @size: size of the buffer pointed to by @buf (in bytes).
281*4882a593Smuzhiyun * @gfp_flags: flags for memory allocation.
282*4882a593Smuzhiyun *
283*4882a593Smuzhiyun * Returns: %0 if ok, negative errno code on error.
284*4882a593Smuzhiyun *
285*4882a593Smuzhiyun * Description:
286*4882a593Smuzhiyun *
287*4882a593Smuzhiyun * Sends a free-form message to user space on the device @wimax_dev.
288*4882a593Smuzhiyun *
289*4882a593Smuzhiyun * NOTES:
290*4882a593Smuzhiyun *
291*4882a593Smuzhiyun * Once the @skb is given to this function, who will own it and will
292*4882a593Smuzhiyun * release it when done (unless it returns error).
293*4882a593Smuzhiyun */
wimax_msg(struct wimax_dev * wimax_dev,const char * pipe_name,const void * buf,size_t size,gfp_t gfp_flags)294*4882a593Smuzhiyun int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
295*4882a593Smuzhiyun const void *buf, size_t size, gfp_t gfp_flags)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun int result = -ENOMEM;
298*4882a593Smuzhiyun struct sk_buff *skb;
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun skb = wimax_msg_alloc(wimax_dev, pipe_name, buf, size, gfp_flags);
301*4882a593Smuzhiyun if (IS_ERR(skb))
302*4882a593Smuzhiyun result = PTR_ERR(skb);
303*4882a593Smuzhiyun else
304*4882a593Smuzhiyun result = wimax_msg_send(wimax_dev, skb);
305*4882a593Smuzhiyun return result;
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(wimax_msg);
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun /*
310*4882a593Smuzhiyun * Relays a message from user space to the driver
311*4882a593Smuzhiyun *
312*4882a593Smuzhiyun * The skb is passed to the driver-specific function with the netlink
313*4882a593Smuzhiyun * and generic netlink headers already stripped.
314*4882a593Smuzhiyun *
315*4882a593Smuzhiyun * This call will block while handling/relaying the message.
316*4882a593Smuzhiyun */
wimax_gnl_doit_msg_from_user(struct sk_buff * skb,struct genl_info * info)317*4882a593Smuzhiyun int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun int result, ifindex;
320*4882a593Smuzhiyun struct wimax_dev *wimax_dev;
321*4882a593Smuzhiyun struct device *dev;
322*4882a593Smuzhiyun struct nlmsghdr *nlh = info->nlhdr;
323*4882a593Smuzhiyun char *pipe_name;
324*4882a593Smuzhiyun void *msg_buf;
325*4882a593Smuzhiyun size_t msg_len;
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun might_sleep();
328*4882a593Smuzhiyun d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info);
329*4882a593Smuzhiyun result = -ENODEV;
330*4882a593Smuzhiyun if (info->attrs[WIMAX_GNL_MSG_IFIDX] == NULL) {
331*4882a593Smuzhiyun pr_err("WIMAX_GNL_MSG_FROM_USER: can't find IFIDX attribute\n");
332*4882a593Smuzhiyun goto error_no_wimax_dev;
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun ifindex = nla_get_u32(info->attrs[WIMAX_GNL_MSG_IFIDX]);
335*4882a593Smuzhiyun wimax_dev = wimax_dev_get_by_genl_info(info, ifindex);
336*4882a593Smuzhiyun if (wimax_dev == NULL)
337*4882a593Smuzhiyun goto error_no_wimax_dev;
338*4882a593Smuzhiyun dev = wimax_dev_to_dev(wimax_dev);
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /* Unpack arguments */
341*4882a593Smuzhiyun result = -EINVAL;
342*4882a593Smuzhiyun if (info->attrs[WIMAX_GNL_MSG_DATA] == NULL) {
343*4882a593Smuzhiyun dev_err(dev, "WIMAX_GNL_MSG_FROM_USER: can't find MSG_DATA "
344*4882a593Smuzhiyun "attribute\n");
345*4882a593Smuzhiyun goto error_no_data;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun msg_buf = nla_data(info->attrs[WIMAX_GNL_MSG_DATA]);
348*4882a593Smuzhiyun msg_len = nla_len(info->attrs[WIMAX_GNL_MSG_DATA]);
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun if (info->attrs[WIMAX_GNL_MSG_PIPE_NAME] == NULL)
351*4882a593Smuzhiyun pipe_name = NULL;
352*4882a593Smuzhiyun else {
353*4882a593Smuzhiyun struct nlattr *attr = info->attrs[WIMAX_GNL_MSG_PIPE_NAME];
354*4882a593Smuzhiyun size_t attr_len = nla_len(attr);
355*4882a593Smuzhiyun /* libnl-1.1 does not yet support NLA_NUL_STRING */
356*4882a593Smuzhiyun result = -ENOMEM;
357*4882a593Smuzhiyun pipe_name = kstrndup(nla_data(attr), attr_len + 1, GFP_KERNEL);
358*4882a593Smuzhiyun if (pipe_name == NULL)
359*4882a593Smuzhiyun goto error_alloc;
360*4882a593Smuzhiyun pipe_name[attr_len] = 0;
361*4882a593Smuzhiyun }
362*4882a593Smuzhiyun mutex_lock(&wimax_dev->mutex);
363*4882a593Smuzhiyun result = wimax_dev_is_ready(wimax_dev);
364*4882a593Smuzhiyun if (result == -ENOMEDIUM)
365*4882a593Smuzhiyun result = 0;
366*4882a593Smuzhiyun if (result < 0)
367*4882a593Smuzhiyun goto error_not_ready;
368*4882a593Smuzhiyun result = -ENOSYS;
369*4882a593Smuzhiyun if (wimax_dev->op_msg_from_user == NULL)
370*4882a593Smuzhiyun goto error_noop;
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun d_printf(1, dev,
373*4882a593Smuzhiyun "CRX: nlmsghdr len %u type %u flags 0x%04x seq 0x%x pid %u\n",
374*4882a593Smuzhiyun nlh->nlmsg_len, nlh->nlmsg_type, nlh->nlmsg_flags,
375*4882a593Smuzhiyun nlh->nlmsg_seq, nlh->nlmsg_pid);
376*4882a593Smuzhiyun d_printf(1, dev, "CRX: wimax message %zu bytes\n", msg_len);
377*4882a593Smuzhiyun d_dump(2, dev, msg_buf, msg_len);
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun result = wimax_dev->op_msg_from_user(wimax_dev, pipe_name,
380*4882a593Smuzhiyun msg_buf, msg_len, info);
381*4882a593Smuzhiyun error_noop:
382*4882a593Smuzhiyun error_not_ready:
383*4882a593Smuzhiyun mutex_unlock(&wimax_dev->mutex);
384*4882a593Smuzhiyun error_alloc:
385*4882a593Smuzhiyun kfree(pipe_name);
386*4882a593Smuzhiyun error_no_data:
387*4882a593Smuzhiyun dev_put(wimax_dev->net_dev);
388*4882a593Smuzhiyun error_no_wimax_dev:
389*4882a593Smuzhiyun d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
390*4882a593Smuzhiyun return result;
391*4882a593Smuzhiyun }
392