libertas: moveing mesh-related functions into mesh.c
[deliverable/linux.git] / drivers / net / wireless / libertas / mesh.c
1 #include <linux/moduleparam.h>
2 #include <linux/delay.h>
3 #include <linux/etherdevice.h>
4 #include <linux/netdevice.h>
5 #include <linux/if_arp.h>
6 #include <linux/kthread.h>
7 #include <linux/kfifo.h>
8
9 #include "mesh.h"
10 #include "decl.h"
11 #include "cmd.h"
12
13
14 /***************************************************************************
15 * Mesh sysfs support
16 */
17
18 /**
19 * Attributes exported through sysfs
20 */
21
22 /**
23 * @brief Get function for sysfs attribute anycast_mask
24 */
25 static ssize_t lbs_anycast_get(struct device *dev,
26 struct device_attribute *attr, char * buf)
27 {
28 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
29 struct cmd_ds_mesh_access mesh_access;
30 int ret;
31
32 memset(&mesh_access, 0, sizeof(mesh_access));
33
34 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
35 if (ret)
36 return ret;
37
38 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
39 }
40
41 /**
42 * @brief Set function for sysfs attribute anycast_mask
43 */
44 static ssize_t lbs_anycast_set(struct device *dev,
45 struct device_attribute *attr, const char * buf, size_t count)
46 {
47 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
48 struct cmd_ds_mesh_access mesh_access;
49 uint32_t datum;
50 int ret;
51
52 memset(&mesh_access, 0, sizeof(mesh_access));
53 sscanf(buf, "%x", &datum);
54 mesh_access.data[0] = cpu_to_le32(datum);
55
56 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
57 if (ret)
58 return ret;
59
60 return strlen(buf);
61 }
62
63 /**
64 * @brief Get function for sysfs attribute prb_rsp_limit
65 */
66 static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
67 struct device_attribute *attr, char *buf)
68 {
69 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
70 struct cmd_ds_mesh_access mesh_access;
71 int ret;
72 u32 retry_limit;
73
74 memset(&mesh_access, 0, sizeof(mesh_access));
75 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
76
77 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
78 &mesh_access);
79 if (ret)
80 return ret;
81
82 retry_limit = le32_to_cpu(mesh_access.data[1]);
83 return snprintf(buf, 10, "%d\n", retry_limit);
84 }
85
86 /**
87 * @brief Set function for sysfs attribute prb_rsp_limit
88 */
89 static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
90 struct device_attribute *attr, const char *buf, size_t count)
91 {
92 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
93 struct cmd_ds_mesh_access mesh_access;
94 int ret;
95 unsigned long retry_limit;
96
97 memset(&mesh_access, 0, sizeof(mesh_access));
98 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
99
100 if (!strict_strtoul(buf, 10, &retry_limit))
101 return -ENOTSUPP;
102 if (retry_limit > 15)
103 return -ENOTSUPP;
104
105 mesh_access.data[1] = cpu_to_le32(retry_limit);
106
107 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
108 &mesh_access);
109 if (ret)
110 return ret;
111
112 return strlen(buf);
113 }
114
115 /**
116 * Get function for sysfs attribute mesh
117 */
118 static ssize_t lbs_mesh_get(struct device *dev,
119 struct device_attribute *attr, char * buf)
120 {
121 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
122 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
123 }
124
125 /**
126 * Set function for sysfs attribute mesh
127 */
128 static ssize_t lbs_mesh_set(struct device *dev,
129 struct device_attribute *attr, const char * buf, size_t count)
130 {
131 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
132 int enable;
133 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
134
135 sscanf(buf, "%x", &enable);
136 enable = !!enable;
137 if (enable == !!priv->mesh_dev)
138 return count;
139 if (enable)
140 action = CMD_ACT_MESH_CONFIG_START;
141 ret = lbs_mesh_config(priv, action, priv->channel);
142 if (ret)
143 return ret;
144
145 if (enable)
146 lbs_add_mesh(priv);
147 else
148 lbs_remove_mesh(priv);
149
150 return count;
151 }
152
153 /**
154 * lbs_mesh attribute to be exported per ethX interface
155 * through sysfs (/sys/class/net/ethX/lbs_mesh)
156 */
157 static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
158
159 /**
160 * anycast_mask attribute to be exported per mshX interface
161 * through sysfs (/sys/class/net/mshX/anycast_mask)
162 */
163 static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
164
165 /**
166 * prb_rsp_limit attribute to be exported per mshX interface
167 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
168 */
169 static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
170 lbs_prb_rsp_limit_set);
171
172 static struct attribute *lbs_mesh_sysfs_entries[] = {
173 &dev_attr_anycast_mask.attr,
174 &dev_attr_prb_rsp_limit.attr,
175 NULL,
176 };
177
178 static struct attribute_group lbs_mesh_attr_group = {
179 .attrs = lbs_mesh_sysfs_entries,
180 };
181
182
183
184 /***************************************************************************
185 * Initializing and starting, stopping mesh
186 */
187
188 /*
189 * Check mesh FW version and appropriately send the mesh start
190 * command
191 */
192 int lbs_init_mesh(struct lbs_private *priv)
193 {
194 struct net_device *dev = priv->dev;
195 int ret = 0;
196
197 lbs_deb_enter(LBS_DEB_MESH);
198
199 if (priv->mesh_fw_ver == MESH_FW_OLD) {
200 /* Enable mesh, if supported, and work out which TLV it uses.
201 0x100 + 291 is an unofficial value used in 5.110.20.pXX
202 0x100 + 37 is the official value used in 5.110.21.pXX
203 but we check them in that order because 20.pXX doesn't
204 give an error -- it just silently fails. */
205
206 /* 5.110.20.pXX firmware will fail the command if the channel
207 doesn't match the existing channel. But only if the TLV
208 is correct. If the channel is wrong, _BOTH_ versions will
209 give an error to 0x100+291, and allow 0x100+37 to succeed.
210 It's just that 5.110.20.pXX will not have done anything
211 useful */
212
213 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
214 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
215 priv->channel)) {
216 priv->mesh_tlv = TLV_TYPE_MESH_ID;
217 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
218 priv->channel))
219 priv->mesh_tlv = 0;
220 }
221 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
222 /* 10.0.0.pXX new firmwares should succeed with TLV
223 * 0x100+37; Do not invoke command with old TLV.
224 */
225 priv->mesh_tlv = TLV_TYPE_MESH_ID;
226 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
227 priv->channel))
228 priv->mesh_tlv = 0;
229 }
230 if (priv->mesh_tlv) {
231 lbs_add_mesh(priv);
232
233 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
234 lbs_pr_err("cannot register lbs_mesh attribute\n");
235
236 ret = 1;
237 }
238
239 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
240 return ret;
241 }
242
243
244 int lbs_deinit_mesh(struct lbs_private *priv)
245 {
246 struct net_device *dev = priv->dev;
247 int ret = 0;
248
249 lbs_deb_enter(LBS_DEB_MESH);
250
251 if (priv->mesh_tlv) {
252 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
253 ret = 1;
254 }
255
256 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
257 return ret;
258 }
259
260
261 /**
262 * @brief This function closes the mshX interface
263 *
264 * @param dev A pointer to net_device structure
265 * @return 0
266 */
267 static int lbs_mesh_stop(struct net_device *dev)
268 {
269 struct lbs_private *priv = dev->ml_priv;
270
271 lbs_deb_enter(LBS_DEB_MESH);
272 spin_lock_irq(&priv->driver_lock);
273
274 priv->mesh_open = 0;
275 priv->mesh_connect_status = LBS_DISCONNECTED;
276
277 netif_stop_queue(dev);
278 netif_carrier_off(dev);
279
280 spin_unlock_irq(&priv->driver_lock);
281
282 schedule_work(&priv->mcast_work);
283
284 lbs_deb_leave(LBS_DEB_MESH);
285 return 0;
286 }
287
288 /**
289 * @brief This function opens the mshX interface
290 *
291 * @param dev A pointer to net_device structure
292 * @return 0 or -EBUSY if monitor mode active
293 */
294 static int lbs_mesh_dev_open(struct net_device *dev)
295 {
296 struct lbs_private *priv = dev->ml_priv;
297 int ret = 0;
298
299 lbs_deb_enter(LBS_DEB_NET);
300
301 spin_lock_irq(&priv->driver_lock);
302
303 if (priv->monitormode) {
304 ret = -EBUSY;
305 goto out;
306 }
307
308 priv->mesh_open = 1;
309 priv->mesh_connect_status = LBS_CONNECTED;
310 netif_carrier_on(dev);
311
312 if (!priv->tx_pending_len)
313 netif_wake_queue(dev);
314 out:
315
316 spin_unlock_irq(&priv->driver_lock);
317 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
318 return ret;
319 }
320
321 static const struct net_device_ops mesh_netdev_ops = {
322 .ndo_open = lbs_mesh_dev_open,
323 .ndo_stop = lbs_mesh_stop,
324 .ndo_start_xmit = lbs_hard_start_xmit,
325 .ndo_set_mac_address = lbs_set_mac_address,
326 .ndo_set_multicast_list = lbs_set_multicast_list,
327 };
328
329 /**
330 * @brief This function adds mshX interface
331 *
332 * @param priv A pointer to the struct lbs_private structure
333 * @return 0 if successful, -X otherwise
334 */
335 int lbs_add_mesh(struct lbs_private *priv)
336 {
337 struct net_device *mesh_dev = NULL;
338 int ret = 0;
339
340 lbs_deb_enter(LBS_DEB_MESH);
341
342 /* Allocate a virtual mesh device */
343 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
344 if (!mesh_dev) {
345 lbs_deb_mesh("init mshX device failed\n");
346 ret = -ENOMEM;
347 goto done;
348 }
349 mesh_dev->ml_priv = priv;
350 priv->mesh_dev = mesh_dev;
351
352 mesh_dev->netdev_ops = &mesh_netdev_ops;
353 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
354 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
355 sizeof(priv->dev->dev_addr));
356
357 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
358
359 #ifdef WIRELESS_EXT
360 mesh_dev->wireless_handlers = &mesh_handler_def;
361 #endif
362 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
363 /* Register virtual mesh interface */
364 ret = register_netdev(mesh_dev);
365 if (ret) {
366 lbs_pr_err("cannot register mshX virtual interface\n");
367 goto err_free;
368 }
369
370 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
371 if (ret)
372 goto err_unregister;
373
374 lbs_persist_config_init(mesh_dev);
375
376 /* Everything successful */
377 ret = 0;
378 goto done;
379
380 err_unregister:
381 unregister_netdev(mesh_dev);
382
383 err_free:
384 free_netdev(mesh_dev);
385
386 done:
387 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
388 return ret;
389 }
390
391 void lbs_remove_mesh(struct lbs_private *priv)
392 {
393 struct net_device *mesh_dev;
394
395 mesh_dev = priv->mesh_dev;
396 if (!mesh_dev)
397 return;
398
399 lbs_deb_enter(LBS_DEB_MESH);
400 netif_stop_queue(mesh_dev);
401 netif_carrier_off(mesh_dev);
402 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
403 lbs_persist_config_remove(mesh_dev);
404 unregister_netdev(mesh_dev);
405 priv->mesh_dev = NULL;
406 free_netdev(mesh_dev);
407 lbs_deb_leave(LBS_DEB_MESH);
408 }
409
410
411
412 /***************************************************************************
413 * Sending and receiving
414 */
415 struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
416 struct net_device *dev, struct rxpd *rxpd)
417 {
418 if (priv->mesh_dev) {
419 if (priv->mesh_fw_ver == MESH_FW_OLD) {
420 if (rxpd->rx_control & RxPD_MESH_FRAME)
421 dev = priv->mesh_dev;
422 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
423 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
424 dev = priv->mesh_dev;
425 }
426 }
427 return dev;
428 }
429
430
431 void lbs_mesh_set_txpd(struct lbs_private *priv,
432 struct net_device *dev, struct txpd *txpd)
433 {
434 if (dev == priv->mesh_dev) {
435 if (priv->mesh_fw_ver == MESH_FW_OLD)
436 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
437 else if (priv->mesh_fw_ver == MESH_FW_NEW)
438 txpd->u.bss.bss_num = MESH_IFACE_ID;
439 }
440 }
441
442
443 /***************************************************************************
444 * Persistent configuration support
445 */
446
447 static int mesh_get_default_parameters(struct device *dev,
448 struct mrvl_mesh_defaults *defs)
449 {
450 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
451 struct cmd_ds_mesh_config cmd;
452 int ret;
453
454 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
455 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
456 CMD_TYPE_MESH_GET_DEFAULTS);
457
458 if (ret)
459 return -EOPNOTSUPP;
460
461 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
462
463 return 0;
464 }
465
466 /**
467 * @brief Get function for sysfs attribute bootflag
468 */
469 static ssize_t bootflag_get(struct device *dev,
470 struct device_attribute *attr, char *buf)
471 {
472 struct mrvl_mesh_defaults defs;
473 int ret;
474
475 ret = mesh_get_default_parameters(dev, &defs);
476
477 if (ret)
478 return ret;
479
480 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
481 }
482
483 /**
484 * @brief Set function for sysfs attribute bootflag
485 */
486 static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
487 const char *buf, size_t count)
488 {
489 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
490 struct cmd_ds_mesh_config cmd;
491 uint32_t datum;
492 int ret;
493
494 memset(&cmd, 0, sizeof(cmd));
495 ret = sscanf(buf, "%d", &datum);
496 if ((ret != 1) || (datum > 1))
497 return -EINVAL;
498
499 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
500 cmd.length = cpu_to_le16(sizeof(uint32_t));
501 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
502 CMD_TYPE_MESH_SET_BOOTFLAG);
503 if (ret)
504 return ret;
505
506 return strlen(buf);
507 }
508
509 /**
510 * @brief Get function for sysfs attribute boottime
511 */
512 static ssize_t boottime_get(struct device *dev,
513 struct device_attribute *attr, char *buf)
514 {
515 struct mrvl_mesh_defaults defs;
516 int ret;
517
518 ret = mesh_get_default_parameters(dev, &defs);
519
520 if (ret)
521 return ret;
522
523 return snprintf(buf, 12, "%d\n", defs.boottime);
524 }
525
526 /**
527 * @brief Set function for sysfs attribute boottime
528 */
529 static ssize_t boottime_set(struct device *dev,
530 struct device_attribute *attr, const char *buf, size_t count)
531 {
532 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
533 struct cmd_ds_mesh_config cmd;
534 uint32_t datum;
535 int ret;
536
537 memset(&cmd, 0, sizeof(cmd));
538 ret = sscanf(buf, "%d", &datum);
539 if ((ret != 1) || (datum > 255))
540 return -EINVAL;
541
542 /* A too small boot time will result in the device booting into
543 * standalone (no-host) mode before the host can take control of it,
544 * so the change will be hard to revert. This may be a desired
545 * feature (e.g to configure a very fast boot time for devices that
546 * will not be attached to a host), but dangerous. So I'm enforcing a
547 * lower limit of 20 seconds: remove and recompile the driver if this
548 * does not work for you.
549 */
550 datum = (datum < 20) ? 20 : datum;
551 cmd.data[0] = datum;
552 cmd.length = cpu_to_le16(sizeof(uint8_t));
553 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
554 CMD_TYPE_MESH_SET_BOOTTIME);
555 if (ret)
556 return ret;
557
558 return strlen(buf);
559 }
560
561 /**
562 * @brief Get function for sysfs attribute channel
563 */
564 static ssize_t channel_get(struct device *dev,
565 struct device_attribute *attr, char *buf)
566 {
567 struct mrvl_mesh_defaults defs;
568 int ret;
569
570 ret = mesh_get_default_parameters(dev, &defs);
571
572 if (ret)
573 return ret;
574
575 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
576 }
577
578 /**
579 * @brief Set function for sysfs attribute channel
580 */
581 static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
582 const char *buf, size_t count)
583 {
584 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
585 struct cmd_ds_mesh_config cmd;
586 uint32_t datum;
587 int ret;
588
589 memset(&cmd, 0, sizeof(cmd));
590 ret = sscanf(buf, "%d", &datum);
591 if (ret != 1 || datum < 1 || datum > 11)
592 return -EINVAL;
593
594 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
595 cmd.length = cpu_to_le16(sizeof(uint16_t));
596 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
597 CMD_TYPE_MESH_SET_DEF_CHANNEL);
598 if (ret)
599 return ret;
600
601 return strlen(buf);
602 }
603
604 /**
605 * @brief Get function for sysfs attribute mesh_id
606 */
607 static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
608 char *buf)
609 {
610 struct mrvl_mesh_defaults defs;
611 int maxlen;
612 int ret;
613
614 ret = mesh_get_default_parameters(dev, &defs);
615
616 if (ret)
617 return ret;
618
619 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
620 lbs_pr_err("inconsistent mesh ID length");
621 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
622 }
623
624 /* SSID not null terminated: reserve room for \0 + \n */
625 maxlen = defs.meshie.val.mesh_id_len + 2;
626 maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
627
628 defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
629
630 return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
631 }
632
633 /**
634 * @brief Set function for sysfs attribute mesh_id
635 */
636 static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
637 const char *buf, size_t count)
638 {
639 struct cmd_ds_mesh_config cmd;
640 struct mrvl_mesh_defaults defs;
641 struct mrvl_meshie *ie;
642 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
643 int len;
644 int ret;
645
646 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
647 return -EINVAL;
648
649 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
650 ie = (struct mrvl_meshie *) &cmd.data[0];
651
652 /* fetch all other Information Element parameters */
653 ret = mesh_get_default_parameters(dev, &defs);
654
655 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
656
657 /* transfer IE elements */
658 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
659
660 len = count - 1;
661 memcpy(ie->val.mesh_id, buf, len);
662 /* SSID len */
663 ie->val.mesh_id_len = len;
664 /* IE len */
665 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
666
667 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
668 CMD_TYPE_MESH_SET_MESH_IE);
669 if (ret)
670 return ret;
671
672 return strlen(buf);
673 }
674
675 /**
676 * @brief Get function for sysfs attribute protocol_id
677 */
678 static ssize_t protocol_id_get(struct device *dev,
679 struct device_attribute *attr, char *buf)
680 {
681 struct mrvl_mesh_defaults defs;
682 int ret;
683
684 ret = mesh_get_default_parameters(dev, &defs);
685
686 if (ret)
687 return ret;
688
689 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
690 }
691
692 /**
693 * @brief Set function for sysfs attribute protocol_id
694 */
695 static ssize_t protocol_id_set(struct device *dev,
696 struct device_attribute *attr, const char *buf, size_t count)
697 {
698 struct cmd_ds_mesh_config cmd;
699 struct mrvl_mesh_defaults defs;
700 struct mrvl_meshie *ie;
701 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
702 uint32_t datum;
703 int ret;
704
705 memset(&cmd, 0, sizeof(cmd));
706 ret = sscanf(buf, "%d", &datum);
707 if ((ret != 1) || (datum > 255))
708 return -EINVAL;
709
710 /* fetch all other Information Element parameters */
711 ret = mesh_get_default_parameters(dev, &defs);
712
713 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
714
715 /* transfer IE elements */
716 ie = (struct mrvl_meshie *) &cmd.data[0];
717 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
718 /* update protocol id */
719 ie->val.active_protocol_id = datum;
720
721 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
722 CMD_TYPE_MESH_SET_MESH_IE);
723 if (ret)
724 return ret;
725
726 return strlen(buf);
727 }
728
729 /**
730 * @brief Get function for sysfs attribute metric_id
731 */
732 static ssize_t metric_id_get(struct device *dev,
733 struct device_attribute *attr, char *buf)
734 {
735 struct mrvl_mesh_defaults defs;
736 int ret;
737
738 ret = mesh_get_default_parameters(dev, &defs);
739
740 if (ret)
741 return ret;
742
743 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
744 }
745
746 /**
747 * @brief Set function for sysfs attribute metric_id
748 */
749 static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
750 const char *buf, size_t count)
751 {
752 struct cmd_ds_mesh_config cmd;
753 struct mrvl_mesh_defaults defs;
754 struct mrvl_meshie *ie;
755 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
756 uint32_t datum;
757 int ret;
758
759 memset(&cmd, 0, sizeof(cmd));
760 ret = sscanf(buf, "%d", &datum);
761 if ((ret != 1) || (datum > 255))
762 return -EINVAL;
763
764 /* fetch all other Information Element parameters */
765 ret = mesh_get_default_parameters(dev, &defs);
766
767 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
768
769 /* transfer IE elements */
770 ie = (struct mrvl_meshie *) &cmd.data[0];
771 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
772 /* update metric id */
773 ie->val.active_metric_id = datum;
774
775 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
776 CMD_TYPE_MESH_SET_MESH_IE);
777 if (ret)
778 return ret;
779
780 return strlen(buf);
781 }
782
783 /**
784 * @brief Get function for sysfs attribute capability
785 */
786 static ssize_t capability_get(struct device *dev,
787 struct device_attribute *attr, char *buf)
788 {
789 struct mrvl_mesh_defaults defs;
790 int ret;
791
792 ret = mesh_get_default_parameters(dev, &defs);
793
794 if (ret)
795 return ret;
796
797 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
798 }
799
800 /**
801 * @brief Set function for sysfs attribute capability
802 */
803 static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
804 const char *buf, size_t count)
805 {
806 struct cmd_ds_mesh_config cmd;
807 struct mrvl_mesh_defaults defs;
808 struct mrvl_meshie *ie;
809 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
810 uint32_t datum;
811 int ret;
812
813 memset(&cmd, 0, sizeof(cmd));
814 ret = sscanf(buf, "%d", &datum);
815 if ((ret != 1) || (datum > 255))
816 return -EINVAL;
817
818 /* fetch all other Information Element parameters */
819 ret = mesh_get_default_parameters(dev, &defs);
820
821 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
822
823 /* transfer IE elements */
824 ie = (struct mrvl_meshie *) &cmd.data[0];
825 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
826 /* update value */
827 ie->val.mesh_capability = datum;
828
829 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
830 CMD_TYPE_MESH_SET_MESH_IE);
831 if (ret)
832 return ret;
833
834 return strlen(buf);
835 }
836
837
838 static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
839 static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
840 static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
841 static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
842 static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
843 static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
844 static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
845
846 static struct attribute *boot_opts_attrs[] = {
847 &dev_attr_bootflag.attr,
848 &dev_attr_boottime.attr,
849 &dev_attr_channel.attr,
850 NULL
851 };
852
853 static struct attribute_group boot_opts_group = {
854 .name = "boot_options",
855 .attrs = boot_opts_attrs,
856 };
857
858 static struct attribute *mesh_ie_attrs[] = {
859 &dev_attr_mesh_id.attr,
860 &dev_attr_protocol_id.attr,
861 &dev_attr_metric_id.attr,
862 &dev_attr_capability.attr,
863 NULL
864 };
865
866 static struct attribute_group mesh_ie_group = {
867 .name = "mesh_ie",
868 .attrs = mesh_ie_attrs,
869 };
870
871 void lbs_persist_config_init(struct net_device *dev)
872 {
873 int ret;
874 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
875 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
876 }
877
878 void lbs_persist_config_remove(struct net_device *dev)
879 {
880 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
881 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
882 }
This page took 0.083928 seconds and 6 git commands to generate.