blob: 8db240b0f82b28f9fe9135601da5ad4fd37aea80 [file] [log] [blame]
Sergey Lapin9ec76712009-06-08 12:18:48 +00001/*
Dmitry Eremin-Solenikov5fd72602010-10-22 01:25:25 +04002 * IEEE 802.15.4 dgram socket interface
Sergey Lapin9ec76712009-06-08 12:18:48 +00003 *
4 * Copyright 2007, 2008 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Sergey Lapin9ec76712009-06-08 12:18:48 +000015 * Written by:
16 * Sergey Lapin <slapin@ossfans.org>
17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
18 */
19
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +020020#include <linux/capability.h>
Sergey Lapin9ec76712009-06-08 12:18:48 +000021#include <linux/net.h>
22#include <linux/module.h>
23#include <linux/if_arp.h>
24#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Alexander Aring4ca24ac2014-10-25 09:41:04 +020026#include <linux/ieee802154.h>
Sergey Lapin9ec76712009-06-08 12:18:48 +000027#include <net/sock.h>
Dmitry Eremin-Solenikovf0166e52009-07-23 16:56:29 +040028#include <net/af_ieee802154.h>
Dmitry Eremin-Solenikovf0166e52009-07-23 16:56:29 +040029#include <net/ieee802154_netdev.h>
Sergey Lapin9ec76712009-06-08 12:18:48 +000030
31#include <asm/ioctls.h>
32
33#include "af802154.h"
34
35static HLIST_HEAD(dgram_head);
36static DEFINE_RWLOCK(dgram_lock);
37
38struct dgram_sock {
39 struct sock sk;
40
Phoebe Buckheistere6278d92014-03-14 21:24:01 +010041 struct ieee802154_addr src_addr;
42 struct ieee802154_addr dst_addr;
Dmitry Baryshkov74eda552009-08-07 02:58:42 +000043
Eric Dumazet95c96172012-04-15 05:58:06 +000044 unsigned int bound:1;
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +020045 unsigned int connected:1;
Eric Dumazet95c96172012-04-15 05:58:06 +000046 unsigned int want_ack:1;
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +020047 unsigned int secen:1;
48 unsigned int secen_override:1;
49 unsigned int seclevel:3;
50 unsigned int seclevel_override:1;
Sergey Lapin9ec76712009-06-08 12:18:48 +000051};
52
53static inline struct dgram_sock *dgram_sk(const struct sock *sk)
54{
55 return container_of(sk, struct dgram_sock, sk);
56}
57
Sergey Lapin9ec76712009-06-08 12:18:48 +000058static void dgram_hash(struct sock *sk)
59{
60 write_lock_bh(&dgram_lock);
61 sk_add_node(sk, &dgram_head);
62 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
63 write_unlock_bh(&dgram_lock);
64}
65
66static void dgram_unhash(struct sock *sk)
67{
68 write_lock_bh(&dgram_lock);
69 if (sk_del_node_init(sk))
70 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
71 write_unlock_bh(&dgram_lock);
72}
73
74static int dgram_init(struct sock *sk)
75{
76 struct dgram_sock *ro = dgram_sk(sk);
77
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +000078 ro->want_ack = 1;
Sergey Lapin9ec76712009-06-08 12:18:48 +000079 return 0;
80}
81
82static void dgram_close(struct sock *sk, long timeout)
83{
84 sk_common_release(sk);
85}
86
87static int dgram_bind(struct sock *sk, struct sockaddr *uaddr, int len)
88{
89 struct sockaddr_ieee802154 *addr = (struct sockaddr_ieee802154 *)uaddr;
Phoebe Buckheistere6278d92014-03-14 21:24:01 +010090 struct ieee802154_addr haddr;
Sergey Lapin9ec76712009-06-08 12:18:48 +000091 struct dgram_sock *ro = dgram_sk(sk);
Dmitry Baryshkov74eda552009-08-07 02:58:42 +000092 int err = -EINVAL;
Sergey Lapin9ec76712009-06-08 12:18:48 +000093 struct net_device *dev;
94
Dmitry Baryshkov74eda552009-08-07 02:58:42 +000095 lock_sock(sk);
96
Sergey Lapin9ec76712009-06-08 12:18:48 +000097 ro->bound = 0;
98
99 if (len < sizeof(*addr))
Dmitry Baryshkov74eda552009-08-07 02:58:42 +0000100 goto out;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000101
102 if (addr->family != AF_IEEE802154)
Dmitry Baryshkov74eda552009-08-07 02:58:42 +0000103 goto out;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000104
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100105 ieee802154_addr_from_sa(&haddr, &addr->addr);
106 dev = ieee802154_get_dev(sock_net(sk), &haddr);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000107 if (!dev) {
108 err = -ENODEV;
109 goto out;
110 }
111
112 if (dev->type != ARPHRD_IEEE802154) {
113 err = -ENODEV;
114 goto out_put;
115 }
116
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100117 ro->src_addr = haddr;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000118
119 ro->bound = 1;
Dmitry Baryshkov74eda552009-08-07 02:58:42 +0000120 err = 0;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000121out_put:
122 dev_put(dev);
123out:
124 release_sock(sk);
125
126 return err;
127}
128
129static int dgram_ioctl(struct sock *sk, int cmd, unsigned long arg)
130{
131 switch (cmd) {
132 case SIOCOUTQ:
133 {
Eric Dumazet31e6d362009-06-17 19:05:41 -0700134 int amount = sk_wmem_alloc_get(sk);
135
Sergey Lapin9ec76712009-06-08 12:18:48 +0000136 return put_user(amount, (int __user *)arg);
137 }
138
139 case SIOCINQ:
140 {
141 struct sk_buff *skb;
142 unsigned long amount;
143
144 amount = 0;
145 spin_lock_bh(&sk->sk_receive_queue.lock);
146 skb = skb_peek(&sk->sk_receive_queue);
147 if (skb != NULL) {
Varka Bhadram4710d802014-07-02 09:01:09 +0530148 /* We will only return the amount
Sergey Lapin9ec76712009-06-08 12:18:48 +0000149 * of this packet since that is all
150 * that will be read.
151 */
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100152 amount = skb->len - ieee802154_hdr_length(skb);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000153 }
154 spin_unlock_bh(&sk->sk_receive_queue.lock);
155 return put_user(amount, (int __user *)arg);
156 }
Sergey Lapin9ec76712009-06-08 12:18:48 +0000157 }
Varka Bhadram4710d802014-07-02 09:01:09 +0530158
Sergey Lapin9ec76712009-06-08 12:18:48 +0000159 return -ENOIOCTLCMD;
160}
161
162/* FIXME: autobind */
163static int dgram_connect(struct sock *sk, struct sockaddr *uaddr,
Varka Bhadram4710d802014-07-02 09:01:09 +0530164 int len)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000165{
166 struct sockaddr_ieee802154 *addr = (struct sockaddr_ieee802154 *)uaddr;
167 struct dgram_sock *ro = dgram_sk(sk);
168 int err = 0;
169
170 if (len < sizeof(*addr))
171 return -EINVAL;
172
173 if (addr->family != AF_IEEE802154)
174 return -EINVAL;
175
176 lock_sock(sk);
177
178 if (!ro->bound) {
179 err = -ENETUNREACH;
180 goto out;
181 }
182
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100183 ieee802154_addr_from_sa(&ro->dst_addr, &addr->addr);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200184 ro->connected = 1;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000185
186out:
187 release_sock(sk);
188 return err;
189}
190
191static int dgram_disconnect(struct sock *sk, int flags)
192{
193 struct dgram_sock *ro = dgram_sk(sk);
194
195 lock_sock(sk);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200196 ro->connected = 0;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000197 release_sock(sk);
198
199 return 0;
200}
201
202static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
Varka Bhadram4710d802014-07-02 09:01:09 +0530203 struct msghdr *msg, size_t size)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000204{
205 struct net_device *dev;
Eric Dumazet95c96172012-04-15 05:58:06 +0000206 unsigned int mtu;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000207 struct sk_buff *skb;
Phoebe Buckheister32edc402014-05-14 17:43:08 +0200208 struct ieee802154_mac_cb *cb;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000209 struct dgram_sock *ro = dgram_sk(sk);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200210 struct ieee802154_addr dst_addr;
Herbert Xuae641942011-11-18 02:20:04 +0000211 int hlen, tlen;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000212 int err;
213
214 if (msg->msg_flags & MSG_OOB) {
215 pr_debug("msg->msg_flags = 0x%x\n", msg->msg_flags);
216 return -EOPNOTSUPP;
217 }
218
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200219 if (!ro->connected && !msg->msg_name)
220 return -EDESTADDRREQ;
221 else if (ro->connected && msg->msg_name)
222 return -EISCONN;
223
Sergey Lapin9ec76712009-06-08 12:18:48 +0000224 if (!ro->bound)
225 dev = dev_getfirstbyhwtype(sock_net(sk), ARPHRD_IEEE802154);
226 else
227 dev = ieee802154_get_dev(sock_net(sk), &ro->src_addr);
228
229 if (!dev) {
230 pr_debug("no dev\n");
231 err = -ENXIO;
232 goto out;
233 }
234 mtu = dev->mtu;
235 pr_debug("name = %s, mtu = %u\n", dev->name, mtu);
236
Sasha Levin3da947b2012-07-02 01:29:55 +0000237 if (size > mtu) {
238 pr_debug("size = %Zu, mtu = %u\n", size, mtu);
Phoebe Buckheisterd1d73582014-03-14 21:24:04 +0100239 err = -EMSGSIZE;
Sasha Levin3da947b2012-07-02 01:29:55 +0000240 goto out_dev;
241 }
242
Herbert Xuae641942011-11-18 02:20:04 +0000243 hlen = LL_RESERVED_SPACE(dev);
244 tlen = dev->needed_tailroom;
245 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
Varka Bhadram4710d802014-07-02 09:01:09 +0530246 msg->msg_flags & MSG_DONTWAIT,
247 &err);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000248 if (!skb)
249 goto out_dev;
250
Herbert Xuae641942011-11-18 02:20:04 +0000251 skb_reserve(skb, hlen);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000252
253 skb_reset_network_header(skb);
254
Phoebe Buckheister32edc402014-05-14 17:43:08 +0200255 cb = mac_cb_init(skb);
256 cb->type = IEEE802154_FC_TYPE_DATA;
257 cb->ackreq = ro->want_ack;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000258
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200259 if (msg->msg_name) {
Varka Bhadram4710d802014-07-02 09:01:09 +0530260 DECLARE_SOCKADDR(struct sockaddr_ieee802154*,
261 daddr, msg->msg_name);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200262
263 ieee802154_addr_from_sa(&dst_addr, &daddr->addr);
264 } else {
265 dst_addr = ro->dst_addr;
266 }
267
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200268 cb->secen = ro->secen;
269 cb->secen_override = ro->secen_override;
270 cb->seclevel = ro->seclevel;
271 cb->seclevel_override = ro->seclevel_override;
272
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200273 err = dev_hard_header(skb, dev, ETH_P_IEEE802154, &dst_addr,
274 ro->bound ? &ro->src_addr : NULL, size);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000275 if (err < 0)
276 goto out_skb;
277
Sergey Lapin9ec76712009-06-08 12:18:48 +0000278 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
279 if (err < 0)
280 goto out_skb;
281
Sergey Lapin9ec76712009-06-08 12:18:48 +0000282 skb->dev = dev;
283 skb->sk = sk;
284 skb->protocol = htons(ETH_P_IEEE802154);
285
286 dev_put(dev);
287
288 err = dev_queue_xmit(skb);
289 if (err > 0)
290 err = net_xmit_errno(err);
291
292 return err ?: size;
293
294out_skb:
295 kfree_skb(skb);
296out_dev:
297 dev_put(dev);
298out:
299 return err;
300}
301
302static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
Varka Bhadram4710d802014-07-02 09:01:09 +0530303 struct msghdr *msg, size_t len, int noblock,
304 int flags, int *addr_len)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000305{
306 size_t copied = 0;
307 int err = -EOPNOTSUPP;
308 struct sk_buff *skb;
Steffen Hurrle342dfc32014-01-17 22:53:15 +0100309 DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000310
311 skb = skb_recv_datagram(sk, flags, noblock, &err);
312 if (!skb)
313 goto out;
314
315 copied = skb->len;
316 if (len < copied) {
317 msg->msg_flags |= MSG_TRUNC;
318 copied = len;
319 }
320
321 /* FIXME: skip headers if necessary ?! */
322 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
323 if (err)
324 goto done;
325
Neil Horman3b885782009-10-12 13:26:31 -0700326 sock_recv_ts_and_drops(msg, sk, skb);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000327
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000328 if (saddr) {
329 saddr->family = AF_IEEE802154;
Phoebe Buckheisterae531b92014-03-14 21:24:02 +0100330 ieee802154_addr_to_sa(&saddr->addr, &mac_cb(skb)->source);
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000331 *addr_len = sizeof(*saddr);
Hannes Frederic Sowabceaa902013-11-18 04:20:45 +0100332 }
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000333
Sergey Lapin9ec76712009-06-08 12:18:48 +0000334 if (flags & MSG_TRUNC)
335 copied = skb->len;
336done:
337 skb_free_datagram(sk, skb);
338out:
339 if (err)
340 return err;
341 return copied;
342}
343
344static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
345{
Phoebe Buckheister8cfad492014-03-17 18:30:19 +0100346 skb = skb_share_check(skb, GFP_ATOMIC);
347 if (!skb)
348 return NET_RX_DROP;
349
Sergey Lapin9ec76712009-06-08 12:18:48 +0000350 if (sock_queue_rcv_skb(sk, skb) < 0) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000351 kfree_skb(skb);
352 return NET_RX_DROP;
353 }
354
355 return NET_RX_SUCCESS;
356}
357
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100358static inline bool
359ieee802154_match_sock(__le64 hw_addr, __le16 pan_id, __le16 short_addr,
360 struct dgram_sock *ro)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000361{
362 if (!ro->bound)
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100363 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000364
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100365 if (ro->src_addr.mode == IEEE802154_ADDR_LONG &&
366 hw_addr == ro->src_addr.extended_addr)
367 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000368
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100369 if (ro->src_addr.mode == IEEE802154_ADDR_SHORT &&
370 pan_id == ro->src_addr.pan_id &&
371 short_addr == ro->src_addr.short_addr)
372 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000373
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100374 return false;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000375}
376
377int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
378{
379 struct sock *sk, *prev = NULL;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000380 int ret = NET_RX_SUCCESS;
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100381 __le16 pan_id, short_addr;
382 __le64 hw_addr;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000383
384 /* Data frame processing */
385 BUG_ON(dev->type != ARPHRD_IEEE802154);
386
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100387 pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
388 short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
389 hw_addr = ieee802154_devaddr_from_raw(dev->dev_addr);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000390
391 read_lock(&dgram_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800392 sk_for_each(sk, &dgram_head) {
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100393 if (ieee802154_match_sock(hw_addr, pan_id, short_addr,
394 dgram_sk(sk))) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000395 if (prev) {
396 struct sk_buff *clone;
Varka Bhadram4710d802014-07-02 09:01:09 +0530397
Sergey Lapin9ec76712009-06-08 12:18:48 +0000398 clone = skb_clone(skb, GFP_ATOMIC);
399 if (clone)
400 dgram_rcv_skb(prev, clone);
401 }
402
403 prev = sk;
404 }
405 }
406
Varka Bhadram4710d802014-07-02 09:01:09 +0530407 if (prev) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000408 dgram_rcv_skb(prev, skb);
Varka Bhadram4710d802014-07-02 09:01:09 +0530409 } else {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000410 kfree_skb(skb);
411 ret = NET_RX_DROP;
412 }
413 read_unlock(&dgram_lock);
414
415 return ret;
416}
417
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400418static int dgram_getsockopt(struct sock *sk, int level, int optname,
Varka Bhadram4710d802014-07-02 09:01:09 +0530419 char __user *optval, int __user *optlen)
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400420{
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000421 struct dgram_sock *ro = dgram_sk(sk);
422
423 int val, len;
424
425 if (level != SOL_IEEE802154)
426 return -EOPNOTSUPP;
427
428 if (get_user(len, optlen))
429 return -EFAULT;
430
431 len = min_t(unsigned int, len, sizeof(int));
432
433 switch (optname) {
434 case WPAN_WANTACK:
435 val = ro->want_ack;
436 break;
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200437 case WPAN_SECURITY:
438 if (!ro->secen_override)
439 val = WPAN_SECURITY_DEFAULT;
440 else if (ro->secen)
441 val = WPAN_SECURITY_ON;
442 else
443 val = WPAN_SECURITY_OFF;
444 break;
445 case WPAN_SECURITY_LEVEL:
446 if (!ro->seclevel_override)
447 val = WPAN_SECURITY_LEVEL_DEFAULT;
448 else
449 val = ro->seclevel;
450 break;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000451 default:
452 return -ENOPROTOOPT;
453 }
454
455 if (put_user(len, optlen))
456 return -EFAULT;
457 if (copy_to_user(optval, &val, len))
458 return -EFAULT;
459 return 0;
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400460}
461
462static int dgram_setsockopt(struct sock *sk, int level, int optname,
Varka Bhadram4710d802014-07-02 09:01:09 +0530463 char __user *optval, unsigned int optlen)
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400464{
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000465 struct dgram_sock *ro = dgram_sk(sk);
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200466 struct net *net = sock_net(sk);
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000467 int val;
468 int err = 0;
469
470 if (optlen < sizeof(int))
471 return -EINVAL;
472
473 if (get_user(val, (int __user *)optval))
474 return -EFAULT;
475
476 lock_sock(sk);
477
478 switch (optname) {
479 case WPAN_WANTACK:
480 ro->want_ack = !!val;
481 break;
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200482 case WPAN_SECURITY:
483 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
484 !ns_capable(net->user_ns, CAP_NET_RAW)) {
485 err = -EPERM;
486 break;
487 }
488
489 switch (val) {
490 case WPAN_SECURITY_DEFAULT:
491 ro->secen_override = 0;
492 break;
493 case WPAN_SECURITY_ON:
494 ro->secen_override = 1;
495 ro->secen = 1;
496 break;
497 case WPAN_SECURITY_OFF:
498 ro->secen_override = 1;
499 ro->secen = 0;
500 break;
501 default:
502 err = -EINVAL;
503 break;
504 }
505 break;
506 case WPAN_SECURITY_LEVEL:
507 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
508 !ns_capable(net->user_ns, CAP_NET_RAW)) {
509 err = -EPERM;
510 break;
511 }
512
513 if (val < WPAN_SECURITY_LEVEL_DEFAULT ||
514 val > IEEE802154_SCF_SECLEVEL_ENC_MIC128) {
515 err = -EINVAL;
516 } else if (val == WPAN_SECURITY_LEVEL_DEFAULT) {
517 ro->seclevel_override = 0;
518 } else {
519 ro->seclevel_override = 1;
520 ro->seclevel = val;
521 }
522 break;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000523 default:
524 err = -ENOPROTOOPT;
525 break;
526 }
527
528 release_sock(sk);
529 return err;
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400530}
531
Sergey Lapin9ec76712009-06-08 12:18:48 +0000532struct proto ieee802154_dgram_prot = {
533 .name = "IEEE-802.15.4-MAC",
534 .owner = THIS_MODULE,
535 .obj_size = sizeof(struct dgram_sock),
536 .init = dgram_init,
537 .close = dgram_close,
538 .bind = dgram_bind,
539 .sendmsg = dgram_sendmsg,
540 .recvmsg = dgram_recvmsg,
541 .hash = dgram_hash,
542 .unhash = dgram_unhash,
543 .connect = dgram_connect,
544 .disconnect = dgram_disconnect,
545 .ioctl = dgram_ioctl,
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400546 .getsockopt = dgram_getsockopt,
547 .setsockopt = dgram_setsockopt,
Sergey Lapin9ec76712009-06-08 12:18:48 +0000548};
549