aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx/wl1251_netlink.c
blob: 1bc049fa2bae98e5fc9d2734c56c57472e9b1284 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/*
 * This file is part of wl12xx
 *
 * Copyright (C) 2008 Nokia Corporation
 *
 * Contact: Kalle Valo <kalle.valo@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */
#include "wl1251_netlink.h"

#include <linux/mutex.h>
#include <linux/socket.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/genetlink.h>
#include <net/wireless.h>
#include <net/mac80211.h>

#include "wl12xx.h"
#include "wl1251_spi.h"
#include "wl1251_acx.h"

/* FIXME: this should be changed as soon as user space catches up */
#define WL12XX_NL_NAME "wl1251"
#define WL12XX_NL_VERSION 1

#define WL12XX_MAX_TEST_LENGTH 1024
#define WL12XX_MAX_NVS_LENGTH 1024

enum wl12xx_nl_commands {
	WL12XX_NL_CMD_UNSPEC,
	WL12XX_NL_CMD_TEST,
	WL12XX_NL_CMD_INTERROGATE,
	WL12XX_NL_CMD_CONFIGURE,
	WL12XX_NL_CMD_PHY_REG_READ,
	WL12XX_NL_CMD_NVS_PUSH,
	WL12XX_NL_CMD_REG_WRITE,
	WL12XX_NL_CMD_REG_READ,
	WL12XX_NL_CMD_SET_PLT_MODE,

	__WL12XX_NL_CMD_AFTER_LAST
};
#define WL12XX_NL_CMD_MAX (__WL12XX_NL_CMD_AFTER_LAST - 1)

enum wl12xx_nl_attrs {
	WL12XX_NL_ATTR_UNSPEC,
	WL12XX_NL_ATTR_IFNAME,
	WL12XX_NL_ATTR_CMD_TEST_PARAM,
	WL12XX_NL_ATTR_CMD_TEST_ANSWER,
	WL12XX_NL_ATTR_CMD_IE,
	WL12XX_NL_ATTR_CMD_IE_LEN,
	WL12XX_NL_ATTR_CMD_IE_BUFFER,
	WL12XX_NL_ATTR_CMD_IE_ANSWER,
	WL12XX_NL_ATTR_REG_ADDR,
	WL12XX_NL_ATTR_REG_VAL,
	WL12XX_NL_ATTR_NVS_BUFFER,
	WL12XX_NL_ATTR_NVS_LEN,
	WL12XX_NL_ATTR_PLT_MODE,

	__WL12XX_NL_ATTR_AFTER_LAST
};
#define WL12XX_NL_ATTR_MAX (__WL12XX_NL_ATTR_AFTER_LAST - 1)

static struct genl_family wl12xx_nl_family = {
	.id = GENL_ID_GENERATE,
	.name = WL12XX_NL_NAME,
	.hdrsize = 0,
	.version = WL12XX_NL_VERSION,
	.maxattr = WL12XX_NL_ATTR_MAX,
};

static struct net_device *ifname_to_netdev(struct net *net,
					   struct genl_info *info)
{
	char *ifname;

	if (!info->attrs[WL12XX_NL_ATTR_IFNAME])
		return NULL;

	ifname = nla_data(info->attrs[WL12XX_NL_ATTR_IFNAME]);

	wl12xx_debug(DEBUG_NETLINK, "Looking for %s", ifname);

	return dev_get_by_name(net, ifname);
}

static struct wl12xx *ifname_to_wl12xx(struct net *net, struct genl_info *info)
{
	struct net_device *netdev;
	struct wireless_dev *wdev;
	struct wiphy *wiphy;
	struct ieee80211_hw *hw;

	netdev = ifname_to_netdev(net, info);
	if (netdev == NULL) {
		wl12xx_error("Wrong interface");
		return NULL;
	}

	wdev = netdev->ieee80211_ptr;
	if (wdev == NULL) {
		wl12xx_error("ieee80211_ptr is NULL");
		return NULL;
	}

	wiphy = wdev->wiphy;
	if (wiphy == NULL) {
		wl12xx_error("wiphy is NULL");
		return NULL;
	}

	hw = wiphy_priv(wiphy);
	if (hw == NULL) {
		wl12xx_error("hw is NULL");
		return NULL;
	}

	dev_put(netdev);

	return hw->priv;
}

static int wl12xx_nl_test_cmd(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	struct wl12xx_command *cmd;
	char *buf;
	int buf_len, ret, cmd_len;
	u8 answer;

	if (!info->attrs[WL12XX_NL_ATTR_CMD_TEST_PARAM])
		return -EINVAL;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		return -EINVAL;
	}

	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
	if (!cmd)
		return -ENOMEM;

	buf = nla_data(info->attrs[WL12XX_NL_ATTR_CMD_TEST_PARAM]);
	buf_len = nla_len(info->attrs[WL12XX_NL_ATTR_CMD_TEST_PARAM]);
	answer = nla_get_u8(info->attrs[WL12XX_NL_ATTR_CMD_TEST_ANSWER]);

	cmd->header.id = CMD_TEST;
	memcpy(cmd->parameters, buf, buf_len);
	cmd_len = sizeof(struct wl12xx_cmd_header) + buf_len;

	mutex_lock(&wl->mutex);
	ret = wl12xx_cmd_test(wl, cmd, cmd_len, answer);
	mutex_unlock(&wl->mutex);

	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto out;
	}

	if (answer) {
		struct sk_buff *msg;
		void *hdr;

		msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
		if (!msg) {
			ret = -ENOMEM;
			goto out;
		}

		hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
				  &wl12xx_nl_family, 0, WL12XX_NL_CMD_TEST);
		if (IS_ERR(hdr)) {
			ret = PTR_ERR(hdr);
			goto nla_put_failure;
		}

		NLA_PUT_STRING(msg, WL12XX_NL_ATTR_IFNAME,
			       nla_data(info->attrs[WL12XX_NL_ATTR_IFNAME]));
		NLA_PUT(msg, WL12XX_NL_ATTR_CMD_TEST_ANSWER,
			sizeof(*cmd), cmd);

		ret = genlmsg_end(msg, hdr);
		if (ret < 0) {
			wl12xx_error("%s() failed", __func__);
			goto nla_put_failure;
		}

		wl12xx_debug(DEBUG_NETLINK, "TEST cmd sent, answer");
		ret = genlmsg_reply(msg, info);
		goto out;

 nla_put_failure:
		nlmsg_free(msg);
	} else
		wl12xx_debug(DEBUG_NETLINK, "TEST cmd sent");

out:
	kfree(cmd);
	return ret;
}

static int wl12xx_nl_interrogate(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	struct sk_buff *msg;
	int ret = -ENOBUFS, cmd_ie, cmd_ie_len;
	struct wl12xx_command *cmd;
	void *hdr;

	if (!info->attrs[WL12XX_NL_ATTR_CMD_IE])
		return -EINVAL;

	if (!info->attrs[WL12XX_NL_ATTR_CMD_IE_LEN])
		return -EINVAL;

	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
	if (!cmd)
		return -ENOMEM;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		ret = -EINVAL;
		goto nla_put_failure;
	}

	/* acx id */
	cmd_ie = nla_get_u32(info->attrs[WL12XX_NL_ATTR_CMD_IE]);

	/* maximum length of acx, including all headers */
	cmd_ie_len = nla_get_u32(info->attrs[WL12XX_NL_ATTR_CMD_IE_LEN]);

	wl12xx_debug(DEBUG_NETLINK, "Getting IE 0x%x (len %d)",
		     cmd_ie, cmd_ie_len);

	mutex_lock(&wl->mutex);
	ret = wl12xx_cmd_interrogate(wl, cmd_ie, cmd, cmd_ie_len);
	mutex_unlock(&wl->mutex);

	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
			  &wl12xx_nl_family, 0, WL12XX_NL_CMD_INTERROGATE);
	if (IS_ERR(hdr)) {
		ret = PTR_ERR(hdr);
		goto nla_put_failure;
	}

	NLA_PUT_STRING(msg, WL12XX_NL_ATTR_IFNAME,
		       nla_data(info->attrs[WL12XX_NL_ATTR_IFNAME]));
	NLA_PUT(msg, WL12XX_NL_ATTR_CMD_IE_ANSWER, cmd_ie_len, cmd);

	ret = genlmsg_end(msg, hdr);
	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	kfree(cmd);
	return genlmsg_reply(msg, info);

 nla_put_failure:
	kfree(cmd);
	nlmsg_free(msg);

	return ret;
}

static int wl12xx_nl_configure(struct sk_buff *skb, struct genl_info *info)
{
	int ret = 0, cmd_ie_len, acx_len;
	struct acx_header *acx = NULL;
	struct sk_buff *msg;
	struct wl12xx *wl;
	void *cmd_ie;
	u16 *id;

	if (!info->attrs[WL12XX_NL_ATTR_CMD_IE_BUFFER])
		return -EINVAL;

	if (!info->attrs[WL12XX_NL_ATTR_CMD_IE_LEN])
		return -EINVAL;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		ret = -EINVAL;
		goto nla_put_failure;
	}

	/* contains the acx header but not the cmd header */
	cmd_ie = nla_data(info->attrs[WL12XX_NL_ATTR_CMD_IE_BUFFER]);

	cmd_ie_len = nla_get_u32(info->attrs[WL12XX_NL_ATTR_CMD_IE_LEN]);

	/* acx id is in the first two bytes */
	id = cmd_ie;

	/* need to add acx_header before cmd_ie, so create a new command */
	acx_len = sizeof(struct acx_header) + cmd_ie_len;
	acx = kzalloc(acx_len, GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto nla_put_failure;
	}

	/* copy the acx header and the payload */
	memcpy(&acx->id, cmd_ie, cmd_ie_len);

	mutex_lock(&wl->mutex);
	ret = wl12xx_cmd_configure(wl, *id, acx, acx_len);
	mutex_unlock(&wl->mutex);

	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	wl12xx_debug(DEBUG_NETLINK, "CONFIGURE cmd sent");

 nla_put_failure:
	kfree(acx);
	nlmsg_free(msg);

	return ret;
}

static int wl12xx_nl_phy_reg_read(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	struct sk_buff *msg;
	u32 reg_addr, *reg_value = NULL;
	int ret = 0;
	void *hdr;

	if (!info->attrs[WL12XX_NL_ATTR_REG_ADDR])
		return -EINVAL;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		ret = -EINVAL;
		goto nla_put_failure;
	}

	reg_value = kmalloc(sizeof(*reg_value), GFP_KERNEL);
	if (!reg_value) {
		ret = -ENOMEM;
		goto nla_put_failure;
	}

	reg_addr = nla_get_u32(info->attrs[WL12XX_NL_ATTR_REG_ADDR]);

	wl12xx_debug(DEBUG_NETLINK, "Reading PHY reg 0x%x", reg_addr);

	mutex_lock(&wl->mutex);
	ret = wl12xx_cmd_read_memory(wl, reg_addr, reg_value,
				     sizeof(*reg_value));
	mutex_unlock(&wl->mutex);

	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}


	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
			  &wl12xx_nl_family, 0, WL12XX_NL_CMD_PHY_REG_READ);
	if (IS_ERR(hdr)) {
		ret = PTR_ERR(hdr);
		goto nla_put_failure;
	}

	NLA_PUT_STRING(msg, WL12XX_NL_ATTR_IFNAME,
		       nla_data(info->attrs[WL12XX_NL_ATTR_IFNAME]));

	NLA_PUT_U32(msg, WL12XX_NL_ATTR_REG_VAL, *reg_value);

	ret = genlmsg_end(msg, hdr);
	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	kfree(reg_value);

	return genlmsg_reply(msg, info);

 nla_put_failure:
	nlmsg_free(msg);
	kfree(reg_value);

	return ret;
}

static int wl12xx_nl_nvs_push(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	int ret = 0;

	if (!info->attrs[WL12XX_NL_ATTR_NVS_BUFFER])
		return -EINVAL;

	if (!info->attrs[WL12XX_NL_ATTR_NVS_LEN])
		return -EINVAL;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		return -EINVAL;
	}

	mutex_lock(&wl->mutex);
	wl->nvs_len = nla_get_u32(info->attrs[WL12XX_NL_ATTR_NVS_LEN]);
	if (wl->nvs_len % 4) {
		wl12xx_error("NVS size is not multiple of 32: %d", wl->nvs_len);
		ret = -EILSEQ;
		goto out;
	}

	/* If we already have an NVS, we should free it */
	kfree(wl->nvs);

	wl->nvs = kzalloc(wl->nvs_len, GFP_KERNEL);
	if (wl->nvs == NULL) {
		wl12xx_error("Can't allocate NVS");
		ret = -ENOMEM;
		goto out;
	}

	memcpy(wl->nvs,
	       nla_data(info->attrs[WL12XX_NL_ATTR_NVS_BUFFER]),
	       wl->nvs_len);

	wl12xx_debug(DEBUG_NETLINK, "got NVS from userspace, %d bytes",
		     wl->nvs_len);

out:
	mutex_unlock(&wl->mutex);

	return ret;
}

static int wl12xx_nl_reg_read(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	u32 addr, val;
	int ret = 0;
	struct sk_buff *msg;
	void *hdr;

	if (!info->attrs[WL12XX_NL_ATTR_REG_ADDR])
		return -EINVAL;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		return -EINVAL;
	}

	addr = nla_get_u32(info->attrs[WL12XX_NL_ATTR_REG_ADDR]);

	mutex_lock(&wl->mutex);
	val = wl12xx_reg_read32(wl, addr);
	mutex_unlock(&wl->mutex);

	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
			  &wl12xx_nl_family, 0, WL12XX_NL_CMD_PHY_REG_READ);
	if (IS_ERR(hdr)) {
		ret = PTR_ERR(hdr);
		goto nla_put_failure;
	}

	NLA_PUT_STRING(msg, WL12XX_NL_ATTR_IFNAME,
		       nla_data(info->attrs[WL12XX_NL_ATTR_IFNAME]));

	NLA_PUT_U32(msg, WL12XX_NL_ATTR_REG_VAL, val);

	ret = genlmsg_end(msg, hdr);
	if (ret < 0) {
		wl12xx_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	return genlmsg_reply(msg, info);

 nla_put_failure:
	nlmsg_free(msg);

	return ret;
}

static int wl12xx_nl_reg_write(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	u32 addr, val;

	if (!info->attrs[WL12XX_NL_ATTR_REG_ADDR])
		return -EINVAL;

	if (!info->attrs[WL12XX_NL_ATTR_REG_VAL])
		return -EINVAL;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		return -EINVAL;
	}

	addr = nla_get_u32(info->attrs[WL12XX_NL_ATTR_REG_ADDR]);
	val = nla_get_u32(info->attrs[WL12XX_NL_ATTR_REG_VAL]);

	mutex_lock(&wl->mutex);
	wl12xx_reg_write32(wl, addr, val);
	mutex_unlock(&wl->mutex);

	return 0;
}

static int wl12xx_nl_set_plt_mode(struct sk_buff *skb, struct genl_info *info)
{
	struct wl12xx *wl;
	u32 val;
	int ret;

	if (!info->attrs[WL12XX_NL_ATTR_PLT_MODE])
		return -EINVAL;

	wl = ifname_to_wl12xx(&init_net, info);
	if (wl == NULL) {
		wl12xx_error("wl12xx not found");
		return -EINVAL;
	}

	val = nla_get_u32(info->attrs[WL12XX_NL_ATTR_PLT_MODE]);

	switch (val) {
	case 0:
		ret = wl12xx_plt_stop(wl);
		break;
	case 1:
		ret = wl12xx_plt_start(wl);
		break;
	default:
		ret = -EINVAL;
		break;
	}

	return ret;
}

static struct nla_policy wl12xx_nl_policy[WL12XX_NL_ATTR_MAX + 1] = {
	[WL12XX_NL_ATTR_IFNAME] =            { .type = NLA_NUL_STRING,
					       .len = IFNAMSIZ-1 },
	[WL12XX_NL_ATTR_CMD_TEST_PARAM] =    { .type = NLA_BINARY,
					       .len = WL12XX_MAX_TEST_LENGTH },
	[WL12XX_NL_ATTR_CMD_TEST_ANSWER] =   { .type = NLA_U8 },
	[WL12XX_NL_ATTR_CMD_IE] =            { .type = NLA_U32 },
	[WL12XX_NL_ATTR_CMD_IE_LEN] =        { .type = NLA_U32 },
	[WL12XX_NL_ATTR_CMD_IE_BUFFER] =     { .type = NLA_BINARY,
					       .len = WL12XX_MAX_TEST_LENGTH },
	[WL12XX_NL_ATTR_CMD_IE_ANSWER] =     { .type = NLA_BINARY,
					       .len = WL12XX_MAX_TEST_LENGTH },
	[WL12XX_NL_ATTR_REG_ADDR] =          { .type = NLA_U32 },
	[WL12XX_NL_ATTR_REG_VAL] =           { .type = NLA_U32 },
	[WL12XX_NL_ATTR_NVS_BUFFER] =        { .type = NLA_BINARY,
					       .len = WL12XX_MAX_NVS_LENGTH },
	[WL12XX_NL_ATTR_NVS_LEN] =           { .type = NLA_U32 },
	[WL12XX_NL_ATTR_PLT_MODE] =          { .type = NLA_U32 },
};

static struct genl_ops wl12xx_nl_ops[] = {
	{
		.cmd = WL12XX_NL_CMD_TEST,
		.doit = wl12xx_nl_test_cmd,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_INTERROGATE,
		.doit = wl12xx_nl_interrogate,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_CONFIGURE,
		.doit = wl12xx_nl_configure,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_PHY_REG_READ,
		.doit = wl12xx_nl_phy_reg_read,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_NVS_PUSH,
		.doit = wl12xx_nl_nvs_push,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_REG_WRITE,
		.doit = wl12xx_nl_reg_write,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_REG_READ,
		.doit = wl12xx_nl_reg_read,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = WL12XX_NL_CMD_SET_PLT_MODE,
		.doit = wl12xx_nl_set_plt_mode,
		.policy = wl12xx_nl_policy,
		.flags = GENL_ADMIN_PERM,
	},
};

int wl12xx_nl_register(void)
{
	int err, i;

	err = genl_register_family(&wl12xx_nl_family);
	if (err)
		return err;

	for (i = 0; i < ARRAY_SIZE(wl12xx_nl_ops); i++) {
		err = genl_register_ops(&wl12xx_nl_family, &wl12xx_nl_ops[i]);
		if (err)
			goto err_out;
	}
	return 0;
 err_out:
	genl_unregister_family(&wl12xx_nl_family);
	return err;
}

void wl12xx_nl_unregister(void)
{
	genl_unregister_family(&wl12xx_nl_family);
}