-
Notifications
You must be signed in to change notification settings - Fork 6
/
dnt900.c
2906 lines (2565 loc) · 110 KB
/
dnt900.c
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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Linux line discipline for RFM DNT900 & DNT2400 radio transceiver
modules.
Copyright (C) 2012, 2013, 2014, 2015 Matthew Hollingworth.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/printk.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/tty_ldisc.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/poll.h>
#include <linux/stat.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/list.h>
#include <linux/completion.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/sysfs.h>
#include <linux/device.h>
#include <linux/string.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/rwsem.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/kfifo.h>
#include <linux/delay.h>
#include <linux/bitops.h>
#include <linux/timer.h>
#define LDISC_NAME "dnt900"
#define CLASS_NAME "dnt900"
#define TTY_DRIVER_NAME "ttyDNT"
#define TTY_DEV_NAME "ttyDNT"
#define LOCAL_SYMLINK_NAME "local"
#define MARK() pr_info("DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__)
#define MAX_PACKET_SIZE (2+255)
// buffer sizes must be powers of 2
#define RX_BUFFER_SIZE (512) // no less
#define TX_BUFFER_SIZE (2048)
#define TTY_BUFFER_SIZE (512)
#define PACKET_BUFFER_SIZE (256)
#define REGISTER_TIMEOUT_MS (10000)
#define STARTUP_DELAY_MS (500)
#define MIN_THROTTLE_MS (20)
#define HOP_DURATION_COUNTS_PER_MS (20)
#define START_OF_PACKET (0xFB)
#define COMMAND_ENTER_PROTOCOL_MODE (0x00)
#define COMMAND_EXIT_PROTOCOL_MODE (0x01)
#define COMMAND_SOFTWARE_RESET (0x02)
#define COMMAND_GET_REGISTER (0x03)
#define COMMAND_SET_REGISTER (0x04)
#define COMMAND_TX_DATA (0x05)
#define COMMAND_DISCOVER (0x06)
#define COMMAND_GET_REMOTE_REGISTER (0x0A)
#define COMMAND_SET_REMOTE_REGISTER (0x0B)
#define COMMAND_JOIN_REPLY (0x0C)
#define COMMAND_REMOTE_LEAVE (0x0D)
#define EVENT_RX_DATA (0x26)
#define EVENT_ANNOUNCE (0x27)
#define EVENT_RX_EVENT (0x28)
#define EVENT_JOIN_REQUEST (0x2C)
#define MASK_COMMAND (0x0F)
#define TYPE_REPLY (0x10)
#define TYPE_EVENT (0x20)
#define STATUS_ACKNOWLEDGED (0x00)
#define STATUS_NOT_ACKNOWLEDGED (0x01)
#define STATUS_NOT_LINKED (0x02)
#define STATUS_HOLDING_FOR_FLOW (0x03)
#define ANNOUNCEMENT_STARTED (0xA0)
#define ANNOUNCEMENT_REMOTE_JOINED (0xA2)
#define ANNOUNCEMENT_JOINED (0xA3)
#define ANNOUNCEMENT_EXITED (0xA4)
#define ANNOUNCEMENT_BASE_REBOOTED (0xA5)
#define ANNOUNCEMENT_REMOTE_EXITED (0xA7)
#define ANNOUNCEMENT_HEARTBEAT (0xA8)
#define ANNOUNCEMENT_HEARTBEAT_TIMEOUT (0xA9)
#define ERROR_PROTOCOL_TYPE (0xE0)
#define ERROR_PROTOCOL_ARGUMENT (0xE1)
#define ERROR_PROTOCOL_GENERAL (0xE2)
#define ERROR_PROTOCOL_TIMEOUT (0xE3)
#define ERROR_PROTOCOL_READONLY (0xE4)
#define ERROR_UART_OVERFLOW (0xE8)
#define ERROR_UART_OVERRUN (0xE9)
#define ERROR_UART_FRAMING (0xEA)
#define ERROR_HARDWARE (0xEE)
#define DEVICE_MODE_REMOTE (0x00)
#define DEVICE_MODE_BASE (0x01)
#define DEVICE_MODE_ROUTER (0x03)
#define PROTOCOL_MODE_ON (0x01)
#define PROTOCOL_OPTIONS_ENABLE_TX_REPLY (0x04)
#define PROTOCOL_OPTIONS_ENABLE_ANNOUNCE (0x01)
#define ANNOUNCE_OPTIONS_LINKS (0x02)
#define ANNOUNCE_OPTIONS_INIT (0x01)
#define AUTH_MODE_ANY (0x00)
#define AUTH_MODE_TABLE (0x01)
#define AUTH_MODE_HOST (0x02)
#define AUTH_MODE_CURRENT (0x03)
#define ACCESS_MODE_POLLING (0x00)
#define ACCESS_MODE_CSMA (0x01)
#define ACCESS_MODE_TDMA_DYNAMIC (0x02)
#define ACCESS_MODE_TDMA_FIXED (0x03)
#define ACCESS_MODE_TDMA_PTT (0x04)
#define PERMIT_STATUS_DENIED (0x00)
#define PERMIT_STATUS_PERMITTED (0x01)
#define LINK_STATUS_READY (0x04)
#define MAX_NETWORK_ID (0x3F)
#define ATTR_R (S_IRUGO)
#define ATTR_W (S_IWUSR)
#define ATTR_RW (S_IRUGO | S_IWUSR)
#define EQUAL_ADDRESSES(address1, address2) ( \
(address1)[0] == (address2)[0] && \
(address1)[1] == (address2)[1] && \
(address1)[2] == (address2)[2])
#define DEV_TO_LOCAL(_dev) container_of(_dev, struct dnt900_local, dev)
#define DEV_TO_RADIO(_dev) container_of(_dev, struct dnt900_radio, dev)
#define RADIO_TO_LOCAL(radio) DEV_TO_LOCAL((radio)->dev.parent)
#define TTY_TO_LOCAL(tty) ((struct dnt900_local *)(tty)->disc_data)
#define TTY_TO_RADIO(tty) DEV_TO_RADIO((tty)->dev->parent)
#define PORT_TO_RADIO(_port) container_of(_port, struct dnt900_radio, port)
#define PRINT_RANGE(buffer, value) do { sprintf(buffer, "%d\n", 46671 * (unsigned char)(value) / 100); } while (0)
#define PRINT_SUCCESS(buffer, attempts_x4) do { sprintf(buffer, "%d\n", (attempts_x4) ? 400 / (unsigned char)(attempts_x4) : 100); } while (0)
#define PRINT_RSSI(buffer, value) do { sprintf(buffer, "%+d\n", (signed char)(value)); } while (0)
#define TRY(expression) do { \
int _err = (expression); \
if (_err) \
return _err; \
} while (0)
#define UNWIND(_err, expression, exit) do { \
_err = (expression); \
if (_err) \
goto exit; \
} while (0)
#define COPY3(dest, src) do { \
(dest)[0] = (src)[0]; \
(dest)[1] = (src)[1]; \
(dest)[2] = (src)[2]; \
} while (0)
#define ARG_COUNT(...) (sizeof((char[]){__VA_ARGS__})/sizeof(char))
#define PACKET(name, ...) unsigned char name[] = { START_OF_PACKET, ARG_COUNT(__VA_ARGS__), __VA_ARGS__ }
struct dnt900_transaction {
struct list_head list;
struct completion completed;
unsigned char *result;
int err;
const unsigned char *packet;
};
struct dnt900_local_params {
unsigned char device_mode;
unsigned char tree_routing_en;
unsigned char slot_size;
unsigned char link_status;
unsigned char base_mac_address[3];
unsigned char base_mode_net_id;
unsigned int hop_duration;
};
struct dnt900_local;
struct dnt900_radio_params {
unsigned char sys_address[3];
unsigned char device_mode;
unsigned char curr_nwk_id;
unsigned char base_mode_net_id;
unsigned char enable_rt_acks;
};
struct dnt900_radio;
struct dnt900_bufdata {
const unsigned char *buf;
unsigned int len;
};
struct dnt900_work {
struct work_struct ws;
unsigned char address[3];
struct dnt900_local *local;
};
struct dnt900_register {
unsigned char bank;
unsigned char offset;
unsigned char span;
};
struct dnt900_reg_attribute {
struct device_attribute attr;
struct dnt900_register reg;
int (*print)(const unsigned char *value, char *buf);
int (*parse)(const char *buf, size_t count, unsigned char *value);
};
struct dnt900_radio_action {
int (*action)(struct dnt900_radio *);
};
struct dnt900_matcher {
void *data;
int (*match)(struct device *, void *);
int (*action)(struct dnt900_radio *);
};
static int dnt900_print_bytes(int bytes, const unsigned char *value, char *buf, size_t size);
static int dnt900_print_1_bytes(const unsigned char *value, char *buf);
static int dnt900_print_2_bytes(const unsigned char *value, char *buf);
static int dnt900_print_3_bytes(const unsigned char *value, char *buf);
static int dnt900_print_4_bytes(const unsigned char *value, char *buf);
static int dnt900_print_hex(int bytes, const unsigned char *value, char *buf, size_t size);
static int dnt900_print_32_hex(const unsigned char *value, char *buf);
static int dnt900_print_8_ascii(const unsigned char *value, char *buf);
static int dnt900_print_16_ascii(const unsigned char *value, char *buf);
static int dnt900_print_5_macs(const unsigned char *value, char *buf);
static int dnt900_parse_bytes(int bytes, const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_1_bytes(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_2_bytes(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_3_bytes(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_4_bytes(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_hex(int bytes, const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_16_hex(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_32_hex(const char *buf, size_t count, unsigned char *value);
static int dnt900_parse_16_ascii(const char *buf, size_t count, unsigned char *value);
static int dnt900_radio_add_attributes(struct dnt900_radio *radio);
static int dnt900_local_add_attributes(struct dnt900_local *local);
static int dnt900_enter_protocol_mode(struct dnt900_local *local);
static int dnt900_get_register(struct dnt900_local *local, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_get_remote_register_simple(struct dnt900_local *local, const unsigned char *sys_address, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_get_remote_register_throttled(struct dnt900_local *local, unsigned int hop_duration, const unsigned char *sys_address, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_get_remote_register(struct dnt900_local *local, const unsigned char *sys_address, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_set_register(struct dnt900_local *local, const struct dnt900_register *reg, const unsigned char *value);
static int dnt900_set_remote_register(struct dnt900_local *local, const unsigned char *sys_address, const struct dnt900_register *reg, const unsigned char *value);
static int dnt900_discover(struct dnt900_local *local, const unsigned char *mac_address, unsigned char *sys_address);
static void dnt900_radio_read_params(struct dnt900_radio *radio, struct dnt900_radio_params *params);
static void dnt900_radio_write_params(struct dnt900_radio *radio, struct dnt900_radio_params *params);
static void dnt900_local_read_params(struct dnt900_local *local, struct dnt900_local_params *params);
static int dnt900_radio_get_register_once(struct dnt900_radio *radio, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_radio_get_register(struct dnt900_radio *radio, const struct dnt900_register *reg, unsigned char *value);
static int dnt900_radio_set_register(struct dnt900_radio *radio, const struct dnt900_register *reg, const unsigned char *value);
static ssize_t dnt900_show_reg(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t dnt900_store_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_store_reset(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_store_discover(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_show_local_attr(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t dnt900_show_radio_attr(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t dnt900_store_join_permit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_store_join_deny(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_store_remap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t dnt900_store_leave(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static int dnt900_local_get_params(struct dnt900_local *local);
static int dnt900_radio_get_params(struct dnt900_radio *radio);
static int dnt900_radio_map_remotes(struct dnt900_radio *radio);
static int dnt900_radio_drop_carriers(struct dnt900_radio *radio);
static int dnt900_radio_hangup_ttys(struct dnt900_radio *radio);
static int dnt900_radio_check_nack(struct dnt900_radio *radio);
static struct dnt900_radio *dnt900_create_radio(struct dnt900_local *local, const unsigned char *mac_address);
static void dnt900_release_radio(struct device *dev);
static int dnt900_add_radio(struct dnt900_local *local, const unsigned char *mac_address);
static int dnt900_unregister_radio(struct device *dev, void *unused);
static int dnt900_radio_matches_sys_address(struct device *dev, void *data);
static int dnt900_radio_matches_mac_address(struct device *dev, void *data);
static int dnt900_radio_is_local(struct device *dev, void *data);
static int dnt900_radio_matches_net_id(struct device *dev, void *data);
static int dnt900_radio_routes_net_id(struct device *dev, void *data);
static int dnt900_radio_in_subnet(struct dnt900_radio *radio, void *data);
static bool dnt900_radio_exists(struct dnt900_local *local, const unsigned char *mac_address);
static int dnt900_dispatch_to_radio(struct dnt900_local *local, void *finder_data, int (*finder)(struct device *, void *), void *action_data, int (*action)(struct dnt900_radio *, void *));
static int dnt900_dispatch_to_radio_no_data(struct dnt900_local *local, void *finder_data, int (*finder)(struct device *, void *), int (*action)(struct dnt900_radio *));
static int dnt900_apply_to_radio(struct device *dev, void *data);
static void dnt900_for_each_radio(struct dnt900_local *local, int (*action)(struct dnt900_radio *));
static int dnt900_apply_to_matching(struct device *dev, void *data);
static void dnt900_for_matching_radios(struct dnt900_local *local, void *data, int (*match)(struct device *, void *), int (*action)(struct dnt900_radio *));
static int dnt900_send_packet(struct dnt900_local *local, const unsigned char *packet);
static int dnt900_send_packet_get_result(struct dnt900_local *local, const unsigned char *packet, unsigned char *result);
static int dnt900_clear_packets(struct dnt900_local *local);
static int dnt900_radio_wake_tty(struct dnt900_radio *radio);
static int dnt900_radio_drop_carrier(struct dnt900_radio *radio);
static int dnt900_radio_raise_carrier(struct dnt900_radio *radio);
static int dnt900_radio_drain_fifo(struct dnt900_radio *radio);
static int dnt900_local_drain_packets(struct dnt900_local *local);
static void dnt900_local_drain_fifo(struct dnt900_local *local);
static int dnt900_tty_port_carrier_raised(struct tty_port *port);
static int dnt900_tty_port_activate(struct tty_port *port, struct tty_struct *tty);
static void dnt900_tty_port_shutdown(struct tty_port *port);
static void dnt900_tty_port_destruct(struct tty_port *port);
static int dnt900_radio_write(struct dnt900_radio *radio, void *data);
static int dnt900_tty_install(struct tty_driver *driver, struct tty_struct *tty);
static int dnt900_tty_open(struct tty_struct *tty, struct file *filp);
static void dnt900_tty_close(struct tty_struct *tty, struct file *filp);
static void dnt900_tty_hangup(struct tty_struct *tty);
static int dnt900_tty_write(struct tty_struct *tty, const unsigned char *buf, int len);
static int dnt900_tty_put_char(struct tty_struct *tty, unsigned char ch);
static int dnt900_tty_write_room(struct tty_struct *tty);
static int dnt900_tty_chars_in_buffer(struct tty_struct *tty);
static void dnt900_tty_flush_chars(struct tty_struct *tty);
static void dnt900_tty_wait_until_sent(struct tty_struct *tty, int timeout);
static void dnt900_tty_flush_buffer(struct tty_struct *tty);
static ssize_t dnt900_ldisc_write(struct tty_struct *tty, struct file *filp, const unsigned char *buf, size_t len);
static void dnt900_ldisc_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count);
static void dnt900_ldisc_write_wakeup(struct tty_struct *tty);
static int dnt900_ldisc_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
static void dnt900_ldisc_flush_buffer(struct tty_struct *tty);
static int dnt900_process_reply(struct dnt900_local *local, unsigned char *response);
static int dnt900_process_event(struct dnt900_local *local, unsigned char *response);
static int dnt900_process_rx_event(struct dnt900_radio *radio, void *data);
static int dnt900_process_announcement(struct dnt900_local *local, unsigned char *annc);
static int dnt900_radio_process_announcement(struct dnt900_radio *radio, void *data);
static int dnt900_process_argument_error(struct dnt900_local *local);
static int dnt900_process_join_request(struct dnt900_local *local, unsigned char *request);
static int dnt900_radio_report_rssi(struct dnt900_radio *radio, void *data);
static int dnt900_radio_check_heartbeat(struct dnt900_radio *radio, void *data);
static int dnt900_radio_out(struct dnt900_radio *radio, void *data);
static void dnt900_schedule_work(struct dnt900_local *local, const unsigned char *address, void (*work_function)(struct work_struct *));
static void dnt900_add_new_mac_address(struct work_struct *ws);
static void dnt900_add_new_sys_address(struct work_struct *ws);
static void dnt900_refresh_radio(struct work_struct *ws);
static void dnt900_refresh_local(struct work_struct *ws);
static void dnt900_init_local(struct work_struct *ws);
static void dnt900_map_remotes(struct work_struct *ws);
static void dnt900_map_all_remotes(struct work_struct *ws);
static irqreturn_t dnt900_cts_handler(int irq, void *dev_id);
static void dnt900_next_remote_read(unsigned long data);
static struct dnt900_local *dnt900_create_local(struct tty_struct *tty);
static void dnt900_unregister_local(struct dnt900_local *local);
static void dnt900_release_local(struct device *dev);
static int dnt900_ldisc_open(struct tty_struct *tty);
static void dnt900_ldisc_close(struct tty_struct *tty);
static int dnt900_ldisc_hangup(struct tty_struct *tty);
#ifndef N_DNT900
#define N_DNT900 29
#endif
static uint n_dnt900 = N_DNT900;
static uint radios = 255;
static int gpio_cts = -1;
static uint hop_delay = 6;
module_param(radios, uint, S_IRUGO);
MODULE_PARM_DESC(radios, "maximum number of radios");
module_param(n_dnt900, uint, S_IRUGO);
MODULE_PARM_DESC(n_dnt900, "line discipline number");
module_param(gpio_cts, int, S_IRUGO);
MODULE_PARM_DESC(gpio_cts, "GPIO number for /HOST_CTS signal");
module_param(hop_delay, uint, S_IRUGO);
MODULE_PARM_DESC(hop_delay, "number of hops delay between remote register reads");
static const struct device_attribute dnt900_local_command_attributes[] = {
__ATTR(reset, ATTR_W, NULL, dnt900_store_reset),
__ATTR(discover, ATTR_W, NULL, dnt900_store_discover),
__ATTR(join_permit, ATTR_W, NULL, dnt900_store_join_permit),
__ATTR(join_deny, ATTR_W, NULL, dnt900_store_join_deny),
__ATTR(remap, ATTR_W, NULL, dnt900_store_remap),
};
static const struct device_attribute dnt900_radio_command_attributes[] = {
__ATTR(leave, ATTR_W, NULL, dnt900_store_leave),
};
enum {
announce = 0,
error,
parent,
join_request,
};
static const struct device_attribute dnt900_local_attributes[] = {
__ATTR(announce, ATTR_R, dnt900_show_local_attr, NULL),
__ATTR(error, ATTR_R, dnt900_show_local_attr, NULL),
__ATTR(parent, ATTR_R, dnt900_show_local_attr, NULL),
__ATTR(join_request, ATTR_R, dnt900_show_local_attr, NULL),
};
enum {
report_GPIO0 = 0,
report_GPIO1,
report_GPIO2,
report_GPIO3,
report_GPIO4,
report_GPIO5,
report_ADC0,
report_ADC1,
report_ADC2,
report_EventFlags,
range,
success_rate,
beacon_rssi,
parent_rssi,
rssi,
};
static const struct device_attribute dnt900_radio_attributes[] = {
__ATTR(report_GPIO0, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_GPIO1, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_GPIO2, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_GPIO3, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_GPIO4, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_GPIO5, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_ADC0, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_ADC1, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_ADC2, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(report_EventFlags, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(range, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(success_rate, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(beacon_rssi, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(parent_rssi, ATTR_R, dnt900_show_radio_attr, NULL),
__ATTR(rssi, ATTR_R, dnt900_show_radio_attr, NULL),
};
enum {
DeviceMode = 0,
RF_DataRate,
HopDuration,
InitialParentNwkID,
SecurityKey,
SleepMode,
WakeResponseTime,
WakeLinkTimeout,
TxPower,
ExtSyncEnable,
DiversityMode,
UserTag,
RegDenialDelay,
RmtTransDestAddr,
TreeRoutingEn,
BaseModeNetID,
StaticNetAddr,
HeartbeatIntrvl,
TreeRoutingSysID,
EnableRtAcks,
FrequencyBand,
AccessMode,
BaseSlotSize,
LeasePeriod,
ARQ_Mode,
ARQ_AttemptLimit,
MaxSlots,
CSMA_Predelay,
CSMA_Backoff,
MaxPropDelay,
LinkDropThreshold,
CSMA_RemtSlotSize,
CSMA_BusyThreshold,
RangingInterval,
AuthMode,
P2PReplyTimeout,
MacAddress,
CurrNwkAddr,
CurrNwkID,
CurrRF_DataRate,
CurrFreqBand,
LinkStatus,
RemoteSlotSize,
TDMA_NumSlots,
TDMA_CurrSlot,
HardwareVersion,
FirmwareVersion,
FirmwareBuildNum,
SuperframeCount,
RSSI_Idle,
RSSI_Last,
CurrTxPower,
CurrAttemptLimit,
CurrRangeDelay,
FirmwareBuildDate,
FirmwareBuildTime,
ModelNumber,
CurrBaseModeNetID,
AveRXPwrOvHopSeq,
// ParentACKQual,
SerialRate,
SerialParams,
SerialControls,
SPI_Mode,
SPI_Divisor,
SPI_Options,
SPI_MasterCmdLen,
SPI_MasterCmdStr,
ProtocolMode,
ProtocolOptions,
TxTimeout,
MinPacketLength,
AnnounceOptions,
TransLinkAnnEn,
ProtocolSequenceEn,
TransPtToPtMode,
MaxPktsPerHop,
GPIO0,
GPIO1,
GPIO2,
GPIO3,
GPIO4,
GPIO5,
ADC0,
ADC1,
ADC2,
EventFlags,
PWM0,
PWM1,
GPIO_Dir,
GPIO_Init,
GPIO_Alt,
GPIO_Edge_Trigger,
GPIO_SleepMode,
GPIO_SleepDir,
GPIO_SleepState,
PWM0_Init,
PWM1_Init,
ADC_SampleIntvl,
ADC0_ThresholdLo,
ADC0_ThresholdHi,
ADC1_ThresholdLo,
ADC1_ThresholdHi,
ADC2_ThresholdLo,
ADC2_ThresholdHi,
IO_ReportTrigger,
IO_ReportInterval,
IO_ReportPreDel,
IO_ReportRepeat,
ApprovedAddr00,
ApprovedAddr01,
ApprovedAddr02,
ApprovedAddr03,
ApprovedAddr04,
ApprovedAddr05,
ApprovedAddr06,
ApprovedAddr07,
ApprovedAddr08,
ApprovedAddr09,
ApprovedAddr10,
ApprovedAddr11,
ApprovedAddr12,
ApprovedAddr13,
ApprovedAddr14,
ApprovedAddr15,
BaseNetworkID,
ParentNetworkID01,
ParentNetworkID02,
ParentNetworkID03,
ParentNetworkID04,
ParentNetworkID05,
ParentNetworkID06,
ParentNetworkID07,
ParentNetworkID08,
ParentNetworkID09,
ParentNetworkID10,
ParentNetworkID11,
ParentNetworkID12,
ParentNetworkID13,
ParentNetworkID14,
ParentNetworkID15,
ParentNetworkID16,
ParentNetworkID17,
ParentNetworkID18,
ParentNetworkID19,
ParentNetworkID20,
ParentNetworkID21,
ParentNetworkID22,
ParentNetworkID23,
ParentNetworkID24,
ParentNetworkID25,
ParentNetworkID26,
ParentNetworkID27,
ParentNetworkID28,
ParentNetworkID29,
ParentNetworkID30,
ParentNetworkID31,
ParentNetworkID32,
ParentNetworkID33,
ParentNetworkID34,
ParentNetworkID35,
ParentNetworkID36,
ParentNetworkID37,
ParentNetworkID38,
ParentNetworkID39,
ParentNetworkID40,
ParentNetworkID41,
ParentNetworkID42,
ParentNetworkID43,
ParentNetworkID44,
ParentNetworkID45,
ParentNetworkID46,
ParentNetworkID47,
ParentNetworkID48,
ParentNetworkID49,
ParentNetworkID50,
ParentNetworkID51,
ParentNetworkID52,
ParentNetworkID53,
ParentNetworkID54,
ParentNetworkID55,
ParentNetworkID56,
ParentNetworkID57,
ParentNetworkID58,
ParentNetworkID59,
ParentNetworkID60,
ParentNetworkID61,
ParentNetworkID62,
ParentNetworkID63,
RegMACAddr00,
RegMACAddr01,
RegMACAddr02,
RegMACAddr03,
RegMACAddr04,
RegMACAddr05,
RegMACAddr06,
RegMACAddr07,
RegMACAddr08,
RegMACAddr09,
RegMACAddr10,
RegMACAddr11,
RegMACAddr12,
RegMACAddr13,
RegMACAddr14,
RegMACAddr15,
RegMACAddr16,
RegMACAddr17,
RegMACAddr18,
RegMACAddr19,
RegMACAddr20,
RegMACAddr21,
RegMACAddr22,
RegMACAddr23,
RegMACAddr24,
RegMACAddr25,
UcReset,
SleepModeOverride,
RoutingTableUpd,
DiagSerialRate,
MemorySave,
};
#define DNT900_REG_ATTR(_name, _mode, _bank, _offset, _span, _print, _parse) { \
.attr = __ATTR(_name, _mode, dnt900_show_reg, dnt900_store_reg), \
.reg = { \
.bank = _bank, \
.offset = _offset, \
.span = _span \
}, \
.print = _print, \
.parse = _parse, \
}
static const struct dnt900_reg_attribute dnt900_reg_attributes[] = {
DNT900_REG_ATTR(DeviceMode, ATTR_RW, 0x00, 0x00, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(RF_DataRate, ATTR_RW, 0x00, 0x01, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(HopDuration, ATTR_RW, 0x00, 0x02, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(InitialParentNwkID, ATTR_RW, 0x00, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SecurityKey, ATTR_W, 0x00, 0x05, 0x10, NULL, dnt900_parse_16_hex),
DNT900_REG_ATTR(SleepMode, ATTR_RW, 0x00, 0x15, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(WakeResponseTime, ATTR_RW, 0x00, 0x16, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(WakeLinkTimeout, ATTR_RW, 0x00, 0x17, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(TxPower, ATTR_RW, 0x00, 0x18, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ExtSyncEnable, ATTR_RW, 0x00, 0x19, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(DiversityMode, ATTR_RW, 0x00, 0x1A, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(UserTag, ATTR_RW, 0x00, 0x1C, 0x10, dnt900_print_16_ascii, dnt900_parse_16_ascii),
DNT900_REG_ATTR(RegDenialDelay, ATTR_RW, 0x00, 0x2C, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(RmtTransDestAddr, ATTR_RW, 0x00, 0x2E, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(TreeRoutingEn, ATTR_RW, 0x00, 0x34, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(BaseModeNetID, ATTR_RW, 0x00, 0x35, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(StaticNetAddr, ATTR_RW, 0x00, 0x36, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(HeartbeatIntrvl, ATTR_RW, 0x00, 0x37, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(TreeRoutingSysID, ATTR_RW, 0x00, 0x39, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(EnableRtAcks, ATTR_RW, 0x00, 0x3A, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(FrequencyBand, ATTR_RW, 0x01, 0x00, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(AccessMode, ATTR_RW, 0x01, 0x01, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(BaseSlotSize, ATTR_RW, 0x01, 0x02, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(LeasePeriod, ATTR_RW, 0x01, 0x03, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ARQ_Mode, ATTR_RW, 0x01, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ARQ_AttemptLimit, ATTR_RW, 0x01, 0x05, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(MaxSlots, ATTR_RW, 0x01, 0x06, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(CSMA_Predelay, ATTR_RW, 0x01, 0x07, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(CSMA_Backoff, ATTR_RW, 0x01, 0x08, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(MaxPropDelay, ATTR_RW, 0x01, 0x09, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(LinkDropThreshold, ATTR_RW, 0x01, 0x0A, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(CSMA_RemtSlotSize, ATTR_RW, 0x01, 0x0B, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(CSMA_BusyThreshold, ATTR_RW, 0x01, 0x0C, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(RangingInterval, ATTR_RW, 0x01, 0x0D, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(AuthMode, ATTR_RW, 0x01, 0x0E, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(P2PReplyTimeout, ATTR_RW, 0x01, 0x0F, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(MacAddress, ATTR_R, 0x02, 0x00, 0x03, dnt900_print_3_bytes, NULL),
DNT900_REG_ATTR(CurrNwkAddr, ATTR_R, 0x02, 0x03, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrNwkID, ATTR_R, 0x02, 0x04, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrRF_DataRate, ATTR_R, 0x02, 0x05, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrFreqBand, ATTR_R, 0x02, 0x06, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(LinkStatus, ATTR_R, 0x02, 0x07, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(RemoteSlotSize, ATTR_R, 0x02, 0x08, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(TDMA_NumSlots, ATTR_R, 0x02, 0x09, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(TDMA_CurrSlot, ATTR_R, 0x02, 0x0B, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(HardwareVersion, ATTR_R, 0x02, 0x0C, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(FirmwareVersion, ATTR_R, 0x02, 0x0D, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(FirmwareBuildNum, ATTR_R, 0x02, 0x0E, 0x02, dnt900_print_2_bytes, NULL),
DNT900_REG_ATTR(SuperframeCount, ATTR_R, 0x02, 0x11, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(RSSI_Idle, ATTR_R, 0x02, 0x12, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(RSSI_Last, ATTR_R, 0x02, 0x13, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrTxPower, ATTR_R, 0x02, 0x14, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrAttemptLimit, ATTR_R, 0x02, 0x15, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrRangeDelay, ATTR_R, 0x02, 0x16, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(FirmwareBuildDate, ATTR_R, 0x02, 0x17, 0x08, dnt900_print_8_ascii, NULL),
DNT900_REG_ATTR(FirmwareBuildTime, ATTR_R, 0x02, 0x1F, 0x08, dnt900_print_8_ascii, NULL),
DNT900_REG_ATTR(ModelNumber, ATTR_R, 0x02, 0x27, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(CurrBaseModeNetID, ATTR_R, 0x02, 0x28, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(AveRXPwrOvHopSeq, ATTR_R, 0x02, 0x29, 0x01, dnt900_print_1_bytes, NULL),
// DNT900_REG_ATTR(ParentACKQual, ATTR_R, 0x02, 0x2A, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(SerialRate, ATTR_RW, 0x03, 0x00, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(SerialParams, ATTR_RW, 0x03, 0x02, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SerialControls, ATTR_RW, 0x03, 0x03, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SPI_Mode, ATTR_RW, 0x03, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SPI_Divisor, ATTR_RW, 0x03, 0x05, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SPI_Options, ATTR_RW, 0x03, 0x06, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SPI_MasterCmdLen, ATTR_RW, 0x03, 0x07, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SPI_MasterCmdStr, ATTR_RW, 0x03, 0x08, 0x20, dnt900_print_32_hex, dnt900_parse_32_hex),
DNT900_REG_ATTR(ProtocolMode, ATTR_RW, 0x04, 0x00, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ProtocolOptions, ATTR_RW, 0x04, 0x01, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(TxTimeout, ATTR_RW, 0x04, 0x02, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(MinPacketLength, ATTR_RW, 0x04, 0x03, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(AnnounceOptions, ATTR_RW, 0x04, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(TransLinkAnnEn, ATTR_RW, 0x04, 0x05, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ProtocolSequenceEn, ATTR_RW, 0x04, 0x06, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(TransPtToPtMode, ATTR_RW, 0x04, 0x07, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(MaxPktsPerHop, ATTR_RW, 0x04, 0x08, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO0, ATTR_RW, 0x05, 0x00, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO1, ATTR_RW, 0x05, 0x01, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO2, ATTR_RW, 0x05, 0x02, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO3, ATTR_RW, 0x05, 0x03, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO4, ATTR_RW, 0x05, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO5, ATTR_RW, 0x05, 0x05, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ADC0, ATTR_R, 0x05, 0x06, 0x02, dnt900_print_2_bytes, NULL),
DNT900_REG_ATTR(ADC1, ATTR_R, 0x05, 0x08, 0x02, dnt900_print_2_bytes, NULL),
DNT900_REG_ATTR(ADC2, ATTR_R, 0x05, 0x0A, 0x02, dnt900_print_2_bytes, NULL),
DNT900_REG_ATTR(EventFlags, ATTR_R, 0x05, 0x0C, 0x02, dnt900_print_2_bytes, NULL),
DNT900_REG_ATTR(PWM0, ATTR_RW, 0x05, 0x0E, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(PWM1, ATTR_RW, 0x05, 0x10, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(GPIO_Dir, ATTR_RW, 0x06, 0x00, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_Init, ATTR_RW, 0x06, 0x01, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_Alt, ATTR_RW, 0x06, 0x02, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_Edge_Trigger, ATTR_RW, 0x06, 0x03, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_SleepMode, ATTR_RW, 0x06, 0x04, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_SleepDir, ATTR_RW, 0x06, 0x05, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(GPIO_SleepState, ATTR_RW, 0x06, 0x06, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(PWM0_Init, ATTR_RW, 0x06, 0x07, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(PWM1_Init, ATTR_RW, 0x06, 0x09, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC_SampleIntvl, ATTR_RW, 0x06, 0x0B, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC0_ThresholdLo, ATTR_RW, 0x06, 0x0D, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC0_ThresholdHi, ATTR_RW, 0x06, 0x0F, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC1_ThresholdLo, ATTR_RW, 0x06, 0x11, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC1_ThresholdHi, ATTR_RW, 0x06, 0x13, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC2_ThresholdLo, ATTR_RW, 0x06, 0x15, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(ADC2_ThresholdHi, ATTR_RW, 0x06, 0x17, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(IO_ReportTrigger, ATTR_RW, 0x06, 0x19, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(IO_ReportInterval, ATTR_RW, 0x06, 0x1A, 0x04, dnt900_print_4_bytes, dnt900_parse_4_bytes),
DNT900_REG_ATTR(IO_ReportPreDel, ATTR_RW, 0x06, 0x1E, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(IO_ReportRepeat, ATTR_RW, 0x06, 0x1F, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(ApprovedAddr00, ATTR_RW, 0x07, 0x00, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr01, ATTR_RW, 0x07, 0x03, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr02, ATTR_RW, 0x07, 0x06, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr03, ATTR_RW, 0x07, 0x09, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr04, ATTR_RW, 0x07, 0x0C, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr05, ATTR_RW, 0x07, 0x0F, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr06, ATTR_RW, 0x07, 0x12, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr07, ATTR_RW, 0x07, 0x15, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr08, ATTR_RW, 0x07, 0x18, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr09, ATTR_RW, 0x07, 0x1B, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr10, ATTR_RW, 0x07, 0x1E, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr11, ATTR_RW, 0x07, 0x21, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr12, ATTR_RW, 0x07, 0x24, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr13, ATTR_RW, 0x07, 0x27, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr14, ATTR_RW, 0x07, 0x2A, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(ApprovedAddr15, ATTR_RW, 0x07, 0x2D, 0x03, dnt900_print_3_bytes, dnt900_parse_3_bytes),
DNT900_REG_ATTR(BaseNetworkID, ATTR_R, 0x08, 0x00, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID01, ATTR_R, 0x08, 0x01, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID02, ATTR_R, 0x08, 0x02, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID03, ATTR_R, 0x08, 0x03, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID04, ATTR_R, 0x08, 0x04, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID05, ATTR_R, 0x08, 0x05, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID06, ATTR_R, 0x08, 0x06, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID07, ATTR_R, 0x08, 0x07, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID08, ATTR_R, 0x08, 0x08, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID09, ATTR_R, 0x08, 0x09, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID10, ATTR_R, 0x08, 0x0A, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID11, ATTR_R, 0x08, 0x0B, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID12, ATTR_R, 0x08, 0x0C, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID13, ATTR_R, 0x08, 0x0D, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID14, ATTR_R, 0x08, 0x0E, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID15, ATTR_R, 0x08, 0x0F, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID16, ATTR_R, 0x08, 0x10, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID17, ATTR_R, 0x08, 0x11, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID18, ATTR_R, 0x08, 0x12, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID19, ATTR_R, 0x08, 0x13, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID20, ATTR_R, 0x08, 0x14, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID21, ATTR_R, 0x08, 0x15, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID22, ATTR_R, 0x08, 0x16, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID23, ATTR_R, 0x08, 0x17, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID24, ATTR_R, 0x08, 0x18, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID25, ATTR_R, 0x08, 0x19, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID26, ATTR_R, 0x08, 0x1A, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID27, ATTR_R, 0x08, 0x1B, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID28, ATTR_R, 0x08, 0x1C, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID29, ATTR_R, 0x08, 0x1D, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID30, ATTR_R, 0x08, 0x1E, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID31, ATTR_R, 0x08, 0x1F, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID32, ATTR_R, 0x08, 0x20, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID33, ATTR_R, 0x08, 0x21, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID34, ATTR_R, 0x08, 0x22, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID35, ATTR_R, 0x08, 0x23, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID36, ATTR_R, 0x08, 0x24, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID37, ATTR_R, 0x08, 0x25, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID38, ATTR_R, 0x08, 0x26, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID39, ATTR_R, 0x08, 0x27, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID40, ATTR_R, 0x08, 0x28, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID41, ATTR_R, 0x08, 0x29, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID42, ATTR_R, 0x08, 0x2A, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID43, ATTR_R, 0x08, 0x2B, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID44, ATTR_R, 0x08, 0x2C, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID45, ATTR_R, 0x08, 0x2D, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID46, ATTR_R, 0x08, 0x2E, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID47, ATTR_R, 0x08, 0x2F, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID48, ATTR_R, 0x08, 0x30, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID49, ATTR_R, 0x08, 0x31, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID50, ATTR_R, 0x08, 0x32, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID51, ATTR_R, 0x08, 0x33, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID52, ATTR_R, 0x08, 0x34, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID53, ATTR_R, 0x08, 0x35, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID54, ATTR_R, 0x08, 0x36, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID55, ATTR_R, 0x08, 0x37, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID56, ATTR_R, 0x08, 0x38, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID57, ATTR_R, 0x08, 0x39, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID58, ATTR_R, 0x08, 0x3A, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID59, ATTR_R, 0x08, 0x3B, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID60, ATTR_R, 0x08, 0x3C, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID61, ATTR_R, 0x08, 0x3D, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID62, ATTR_R, 0x08, 0x3E, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(ParentNetworkID63, ATTR_R, 0x08, 0x3F, 0x01, dnt900_print_1_bytes, NULL),
DNT900_REG_ATTR(RegMACAddr00, ATTR_R, 0x09, 0x00, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr01, ATTR_R, 0x09, 0x01, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr02, ATTR_R, 0x09, 0x02, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr03, ATTR_R, 0x09, 0x03, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr04, ATTR_R, 0x09, 0x04, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr05, ATTR_R, 0x09, 0x05, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr06, ATTR_R, 0x09, 0x06, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr07, ATTR_R, 0x09, 0x07, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr08, ATTR_R, 0x09, 0x08, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr09, ATTR_R, 0x09, 0x09, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr10, ATTR_R, 0x09, 0x0A, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr11, ATTR_R, 0x09, 0x0B, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr12, ATTR_R, 0x09, 0x0C, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr13, ATTR_R, 0x09, 0x0D, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr14, ATTR_R, 0x09, 0x0E, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr15, ATTR_R, 0x09, 0x0F, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr16, ATTR_R, 0x09, 0x10, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr17, ATTR_R, 0x09, 0x11, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr18, ATTR_R, 0x09, 0x12, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr19, ATTR_R, 0x09, 0x13, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr20, ATTR_R, 0x09, 0x14, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr21, ATTR_R, 0x09, 0x15, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr22, ATTR_R, 0x09, 0x16, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr23, ATTR_R, 0x09, 0x17, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr24, ATTR_R, 0x09, 0x18, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(RegMACAddr25, ATTR_R, 0x09, 0x19, 0x0F, dnt900_print_5_macs, NULL),
DNT900_REG_ATTR(UcReset, ATTR_W, 0xFF, 0x00, 0x01, NULL, dnt900_parse_1_bytes),
DNT900_REG_ATTR(SleepModeOverride, ATTR_RW, 0xFF, 0x0C, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(RoutingTableUpd, ATTR_RW, 0xFF, 0x1C, 0x01, dnt900_print_1_bytes, dnt900_parse_1_bytes),
DNT900_REG_ATTR(DiagSerialRate, ATTR_RW, 0xFF, 0x20, 0x02, dnt900_print_2_bytes, dnt900_parse_2_bytes),
DNT900_REG_ATTR(MemorySave, ATTR_W, 0xFF, 0xFF, 0x01, NULL, dnt900_parse_1_bytes),
};
#define REG(name) (&dnt900_reg_attributes[(name)].reg)
struct dnt900_local {
struct device dev;
struct tty_struct *tty;
int gpio_cts;
struct list_head transactions;
struct mutex transactions_lock;
struct mutex radios_lock;
struct mutex remote_read_lock;
struct rw_semaphore closed_lock;
spinlock_t param_lock;
spinlock_t tx_fifo_lock;
spinlock_t rx_fifo_lock;
spinlock_t packet_fifo_lock;
spinlock_t attributes_lock;
struct workqueue_struct *workqueue;
struct dnt900_local_params params;
unsigned char mac_address[3];
DECLARE_KFIFO(rx_fifo, unsigned char, RX_BUFFER_SIZE);
DECLARE_KFIFO(tx_fifo, unsigned char, TX_BUFFER_SIZE);
DECLARE_KFIFO(packet_fifo, unsigned char, PACKET_BUFFER_SIZE);
wait_queue_head_t tx_queue;
wait_queue_head_t remote_read_queue;
struct timer_list remote_read_timer;
unsigned char attributes[ARRAY_SIZE(dnt900_local_attributes)][32];
};
struct dnt900_radio {
struct device dev;
bool is_local;
spinlock_t param_lock;
spinlock_t attributes_lock;
spinlock_t carrier_lock;
unsigned char mac_address[3];
struct dnt900_radio_params params;
char name[80];
struct tty_port port;
int tty_index;
int carrier;
DECLARE_KFIFO(fifo, unsigned char, TTY_BUFFER_SIZE);
unsigned char attributes[ARRAY_SIZE(dnt900_radio_attributes)][8];
};
static struct class *dnt900_class;
static struct tty_driver *dnt900_tty_driver;
static bool *dnt900_tty_indices;
static spinlock_t dnt900_ttys_lock;
static struct tty_ldisc_ops dnt900_ldisc_ops = {
.magic = TTY_LDISC_MAGIC,
.name = LDISC_NAME,
.open = dnt900_ldisc_open,
.close = dnt900_ldisc_close,
.hangup = dnt900_ldisc_hangup,