blob: 2c7a93e7167e97bc22b949812550a46e2f48be9d [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 }
157
158 }
Varka Bhadram4710d802014-07-02 09:01:09 +0530159
Sergey Lapin9ec76712009-06-08 12:18:48 +0000160 return -ENOIOCTLCMD;
161}
162
163/* FIXME: autobind */
164static int dgram_connect(struct sock *sk, struct sockaddr *uaddr,
Varka Bhadram4710d802014-07-02 09:01:09 +0530165 int len)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000166{
167 struct sockaddr_ieee802154 *addr = (struct sockaddr_ieee802154 *)uaddr;
168 struct dgram_sock *ro = dgram_sk(sk);
169 int err = 0;
170
171 if (len < sizeof(*addr))
172 return -EINVAL;
173
174 if (addr->family != AF_IEEE802154)
175 return -EINVAL;
176
177 lock_sock(sk);
178
179 if (!ro->bound) {
180 err = -ENETUNREACH;
181 goto out;
182 }
183
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100184 ieee802154_addr_from_sa(&ro->dst_addr, &addr->addr);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200185 ro->connected = 1;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000186
187out:
188 release_sock(sk);
189 return err;
190}
191
192static int dgram_disconnect(struct sock *sk, int flags)
193{
194 struct dgram_sock *ro = dgram_sk(sk);
195
196 lock_sock(sk);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200197 ro->connected = 0;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000198 release_sock(sk);
199
200 return 0;
201}
202
203static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
Varka Bhadram4710d802014-07-02 09:01:09 +0530204 struct msghdr *msg, size_t size)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000205{
206 struct net_device *dev;
Eric Dumazet95c96172012-04-15 05:58:06 +0000207 unsigned int mtu;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000208 struct sk_buff *skb;
Phoebe Buckheister32edc402014-05-14 17:43:08 +0200209 struct ieee802154_mac_cb *cb;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000210 struct dgram_sock *ro = dgram_sk(sk);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200211 struct ieee802154_addr dst_addr;
Herbert Xuae641942011-11-18 02:20:04 +0000212 int hlen, tlen;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000213 int err;
214
215 if (msg->msg_flags & MSG_OOB) {
216 pr_debug("msg->msg_flags = 0x%x\n", msg->msg_flags);
217 return -EOPNOTSUPP;
218 }
219
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200220 if (!ro->connected && !msg->msg_name)
221 return -EDESTADDRREQ;
222 else if (ro->connected && msg->msg_name)
223 return -EISCONN;
224
Sergey Lapin9ec76712009-06-08 12:18:48 +0000225 if (!ro->bound)
226 dev = dev_getfirstbyhwtype(sock_net(sk), ARPHRD_IEEE802154);
227 else
228 dev = ieee802154_get_dev(sock_net(sk), &ro->src_addr);
229
230 if (!dev) {
231 pr_debug("no dev\n");
232 err = -ENXIO;
233 goto out;
234 }
235 mtu = dev->mtu;
236 pr_debug("name = %s, mtu = %u\n", dev->name, mtu);
237
Sasha Levin3da947b2012-07-02 01:29:55 +0000238 if (size > mtu) {
239 pr_debug("size = %Zu, mtu = %u\n", size, mtu);
Phoebe Buckheisterd1d73582014-03-14 21:24:04 +0100240 err = -EMSGSIZE;
Sasha Levin3da947b2012-07-02 01:29:55 +0000241 goto out_dev;
242 }
243
Herbert Xuae641942011-11-18 02:20:04 +0000244 hlen = LL_RESERVED_SPACE(dev);
245 tlen = dev->needed_tailroom;
246 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
Varka Bhadram4710d802014-07-02 09:01:09 +0530247 msg->msg_flags & MSG_DONTWAIT,
248 &err);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000249 if (!skb)
250 goto out_dev;
251
Herbert Xuae641942011-11-18 02:20:04 +0000252 skb_reserve(skb, hlen);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000253
254 skb_reset_network_header(skb);
255
Phoebe Buckheister32edc402014-05-14 17:43:08 +0200256 cb = mac_cb_init(skb);
257 cb->type = IEEE802154_FC_TYPE_DATA;
258 cb->ackreq = ro->want_ack;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000259
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200260 if (msg->msg_name) {
Varka Bhadram4710d802014-07-02 09:01:09 +0530261 DECLARE_SOCKADDR(struct sockaddr_ieee802154*,
262 daddr, msg->msg_name);
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200263
264 ieee802154_addr_from_sa(&dst_addr, &daddr->addr);
265 } else {
266 dst_addr = ro->dst_addr;
267 }
268
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200269 cb->secen = ro->secen;
270 cb->secen_override = ro->secen_override;
271 cb->seclevel = ro->seclevel;
272 cb->seclevel_override = ro->seclevel_override;
273
Phoebe Buckheister1cc76e32014-05-14 17:43:10 +0200274 err = dev_hard_header(skb, dev, ETH_P_IEEE802154, &dst_addr,
275 ro->bound ? &ro->src_addr : NULL, size);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000276 if (err < 0)
277 goto out_skb;
278
Al Viro6ce8e9c2014-04-06 21:25:44 -0400279 err = memcpy_from_msg(skb_put(skb, size), msg, size);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000280 if (err < 0)
281 goto out_skb;
282
Sergey Lapin9ec76712009-06-08 12:18:48 +0000283 skb->dev = dev;
284 skb->sk = sk;
285 skb->protocol = htons(ETH_P_IEEE802154);
286
287 dev_put(dev);
288
289 err = dev_queue_xmit(skb);
290 if (err > 0)
291 err = net_xmit_errno(err);
292
293 return err ?: size;
294
295out_skb:
296 kfree_skb(skb);
297out_dev:
298 dev_put(dev);
299out:
300 return err;
301}
302
303static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
Varka Bhadram4710d802014-07-02 09:01:09 +0530304 struct msghdr *msg, size_t len, int noblock,
305 int flags, int *addr_len)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000306{
307 size_t copied = 0;
308 int err = -EOPNOTSUPP;
309 struct sk_buff *skb;
Steffen Hurrle342dfc32014-01-17 22:53:15 +0100310 DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000311
312 skb = skb_recv_datagram(sk, flags, noblock, &err);
313 if (!skb)
314 goto out;
315
316 copied = skb->len;
317 if (len < copied) {
318 msg->msg_flags |= MSG_TRUNC;
319 copied = len;
320 }
321
322 /* FIXME: skip headers if necessary ?! */
David S. Miller51f3d022014-11-05 16:46:40 -0500323 err = skb_copy_datagram_msg(skb, 0, msg, copied);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000324 if (err)
325 goto done;
326
Neil Horman3b885782009-10-12 13:26:31 -0700327 sock_recv_ts_and_drops(msg, sk, skb);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000328
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000329 if (saddr) {
330 saddr->family = AF_IEEE802154;
Phoebe Buckheisterae531b92014-03-14 21:24:02 +0100331 ieee802154_addr_to_sa(&saddr->addr, &mac_cb(skb)->source);
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000332 *addr_len = sizeof(*saddr);
Hannes Frederic Sowabceaa902013-11-18 04:20:45 +0100333 }
Stephen Röttger6364e6e2013-03-26 12:41:29 +0000334
Sergey Lapin9ec76712009-06-08 12:18:48 +0000335 if (flags & MSG_TRUNC)
336 copied = skb->len;
337done:
338 skb_free_datagram(sk, skb);
339out:
340 if (err)
341 return err;
342 return copied;
343}
344
345static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
346{
Phoebe Buckheister8cfad492014-03-17 18:30:19 +0100347 skb = skb_share_check(skb, GFP_ATOMIC);
348 if (!skb)
349 return NET_RX_DROP;
350
Sergey Lapin9ec76712009-06-08 12:18:48 +0000351 if (sock_queue_rcv_skb(sk, skb) < 0) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000352 kfree_skb(skb);
353 return NET_RX_DROP;
354 }
355
356 return NET_RX_SUCCESS;
357}
358
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100359static inline bool
360ieee802154_match_sock(__le64 hw_addr, __le16 pan_id, __le16 short_addr,
361 struct dgram_sock *ro)
Sergey Lapin9ec76712009-06-08 12:18:48 +0000362{
363 if (!ro->bound)
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100364 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000365
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100366 if (ro->src_addr.mode == IEEE802154_ADDR_LONG &&
367 hw_addr == ro->src_addr.extended_addr)
368 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000369
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100370 if (ro->src_addr.mode == IEEE802154_ADDR_SHORT &&
371 pan_id == ro->src_addr.pan_id &&
372 short_addr == ro->src_addr.short_addr)
373 return true;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000374
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100375 return false;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000376}
377
378int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
379{
380 struct sock *sk, *prev = NULL;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000381 int ret = NET_RX_SUCCESS;
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100382 __le16 pan_id, short_addr;
383 __le64 hw_addr;
Sergey Lapin9ec76712009-06-08 12:18:48 +0000384
385 /* Data frame processing */
386 BUG_ON(dev->type != ARPHRD_IEEE802154);
387
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100388 pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
389 short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
390 hw_addr = ieee802154_devaddr_from_raw(dev->dev_addr);
Sergey Lapin9ec76712009-06-08 12:18:48 +0000391
392 read_lock(&dgram_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800393 sk_for_each(sk, &dgram_head) {
Phoebe Buckheistere6278d92014-03-14 21:24:01 +0100394 if (ieee802154_match_sock(hw_addr, pan_id, short_addr,
395 dgram_sk(sk))) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000396 if (prev) {
397 struct sk_buff *clone;
Varka Bhadram4710d802014-07-02 09:01:09 +0530398
Sergey Lapin9ec76712009-06-08 12:18:48 +0000399 clone = skb_clone(skb, GFP_ATOMIC);
400 if (clone)
401 dgram_rcv_skb(prev, clone);
402 }
403
404 prev = sk;
405 }
406 }
407
Varka Bhadram4710d802014-07-02 09:01:09 +0530408 if (prev) {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000409 dgram_rcv_skb(prev, skb);
Varka Bhadram4710d802014-07-02 09:01:09 +0530410 } else {
Sergey Lapin9ec76712009-06-08 12:18:48 +0000411 kfree_skb(skb);
412 ret = NET_RX_DROP;
413 }
414 read_unlock(&dgram_lock);
415
416 return ret;
417}
418
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400419static int dgram_getsockopt(struct sock *sk, int level, int optname,
Varka Bhadram4710d802014-07-02 09:01:09 +0530420 char __user *optval, int __user *optlen)
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400421{
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000422 struct dgram_sock *ro = dgram_sk(sk);
423
424 int val, len;
425
426 if (level != SOL_IEEE802154)
427 return -EOPNOTSUPP;
428
429 if (get_user(len, optlen))
430 return -EFAULT;
431
432 len = min_t(unsigned int, len, sizeof(int));
433
434 switch (optname) {
435 case WPAN_WANTACK:
436 val = ro->want_ack;
437 break;
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200438 case WPAN_SECURITY:
439 if (!ro->secen_override)
440 val = WPAN_SECURITY_DEFAULT;
441 else if (ro->secen)
442 val = WPAN_SECURITY_ON;
443 else
444 val = WPAN_SECURITY_OFF;
445 break;
446 case WPAN_SECURITY_LEVEL:
447 if (!ro->seclevel_override)
448 val = WPAN_SECURITY_LEVEL_DEFAULT;
449 else
450 val = ro->seclevel;
451 break;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000452 default:
453 return -ENOPROTOOPT;
454 }
455
456 if (put_user(len, optlen))
457 return -EFAULT;
458 if (copy_to_user(optval, &val, len))
459 return -EFAULT;
460 return 0;
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400461}
462
463static int dgram_setsockopt(struct sock *sk, int level, int optname,
Varka Bhadram4710d802014-07-02 09:01:09 +0530464 char __user *optval, unsigned int optlen)
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400465{
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000466 struct dgram_sock *ro = dgram_sk(sk);
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200467 struct net *net = sock_net(sk);
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000468 int val;
469 int err = 0;
470
471 if (optlen < sizeof(int))
472 return -EINVAL;
473
474 if (get_user(val, (int __user *)optval))
475 return -EFAULT;
476
477 lock_sock(sk);
478
479 switch (optname) {
480 case WPAN_WANTACK:
481 ro->want_ack = !!val;
482 break;
Phoebe Buckheisteraf9eed52014-05-16 17:46:41 +0200483 case WPAN_SECURITY:
484 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
485 !ns_capable(net->user_ns, CAP_NET_RAW)) {
486 err = -EPERM;
487 break;
488 }
489
490 switch (val) {
491 case WPAN_SECURITY_DEFAULT:
492 ro->secen_override = 0;
493 break;
494 case WPAN_SECURITY_ON:
495 ro->secen_override = 1;
496 ro->secen = 1;
497 break;
498 case WPAN_SECURITY_OFF:
499 ro->secen_override = 1;
500 ro->secen = 0;
501 break;
502 default:
503 err = -EINVAL;
504 break;
505 }
506 break;
507 case WPAN_SECURITY_LEVEL:
508 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
509 !ns_capable(net->user_ns, CAP_NET_RAW)) {
510 err = -EPERM;
511 break;
512 }
513
514 if (val < WPAN_SECURITY_LEVEL_DEFAULT ||
515 val > IEEE802154_SCF_SECLEVEL_ENC_MIC128) {
516 err = -EINVAL;
517 } else if (val == WPAN_SECURITY_LEVEL_DEFAULT) {
518 ro->seclevel_override = 0;
519 } else {
520 ro->seclevel_override = 1;
521 ro->seclevel = val;
522 }
523 break;
Dmitry Baryshkov99eb8552009-08-07 02:58:43 +0000524 default:
525 err = -ENOPROTOOPT;
526 break;
527 }
528
529 release_sock(sk);
530 return err;
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400531}
532
Sergey Lapin9ec76712009-06-08 12:18:48 +0000533struct proto ieee802154_dgram_prot = {
534 .name = "IEEE-802.15.4-MAC",
535 .owner = THIS_MODULE,
536 .obj_size = sizeof(struct dgram_sock),
537 .init = dgram_init,
538 .close = dgram_close,
539 .bind = dgram_bind,
540 .sendmsg = dgram_sendmsg,
541 .recvmsg = dgram_recvmsg,
542 .hash = dgram_hash,
543 .unhash = dgram_unhash,
544 .connect = dgram_connect,
545 .disconnect = dgram_disconnect,
546 .ioctl = dgram_ioctl,
Dmitry Eremin-Solenikova9dfac32009-08-03 17:53:00 +0400547 .getsockopt = dgram_getsockopt,
548 .setsockopt = dgram_setsockopt,
Sergey Lapin9ec76712009-06-08 12:18:48 +0000549};
550