-
Notifications
You must be signed in to change notification settings - Fork 6
/
n_xbee.c
executable file
·766 lines (568 loc) · 18.4 KB
/
n_xbee.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
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/interrupt.h> /* mark_bh */
#include <linux/tty.h>
#include <linux/in.h>
#include <linux/netdevice.h> /* struct device, and other headers */
#include <linux/etherdevice.h> /* eth_type_trans */
#include <linux/ip.h> /* struct iphdr */
#include <linux/tcp.h> /* struct tcphdr */
#include <linux/skbuff.h>
#include <linux/udp.h>
#include <linux/ip.h>
#include <net/checksum.h>
#include "n_xbee.h"
/*
**************Network functions************
*/
/*
* Open and close
*/
int xbee_open(struct net_device *dev)
{
printk(KERN_ALERT "[NET open called ]\n");
/* request_region(), request_irq(), .... (like fops->open) */
/*
* Assign the hardware address of the board: use "\0XBEEx", where
* x is 0 or 1. The first byte is '\0' to avoid being a multicast
* address (the first byte of multicast addrs is odd).
*/
//TODO: This should be set to the actual Xbee address somehow, even though it's never used
memcpy(dev->dev_addr, "\0XBEE111", 8);
memcpy(dev->perm_addr, "\0XBEE111", 8);
netif_start_queue(dev);
return 0;
}
int xbee_release(struct net_device *dev)
{
printk(KERN_ALERT "[NET release called ]\n");
/* release ports, irq and such -- like fops->close */
netif_stop_queue(dev); /* can't transmit any more */
return 0;
}
/*
* Configuration changes (passed on by ifconfig)
*/
int xbee_config(struct net_device *dev, struct ifmap *map)
{
//printk(KERN_ALERT "[NET config called ]\n");
if (dev->flags & IFF_UP) /* can't act on a running interface */
return -EBUSY;
/* Don't allow changing the I/O address */
if (map->base_addr != dev->base_addr) {
printk(KERN_WARNING "xbee: Can't change I/O address\n");
return -EOPNOTSUPP;
}
/* Allow changing the IRQ */
if (map->irq != dev->irq) {
dev->irq = map->irq;
/* request_irq() is delayed to open-time */
}
/* ignore other fields */
return 0;
}
/*
* Encapsulate a packet with UDP/IP and hand off to upper networking layers
*/
void xbee_rx(struct net_device *dev, unsigned char *data, int len) {
struct xbee_priv *priv = netdev_priv(dev);
struct sk_buff *skb;
struct iphdr *ih;
int packet_stat;
skb = dev_alloc_skb(len + sizeof(struct udphdr) + sizeof(struct iphdr));
if (!skb) {
if (printk_ratelimit())
printk(KERN_NOTICE "[NET] xbee rx: low on mem - packet dropped\n");
priv->stats.rx_dropped++;
return;
}
skb_reserve (skb, sizeof(struct iphdr) + sizeof(struct udphdr));
// Put all the data into a new socket buffer
memcpy(skb_put(skb, len), data, len);
// Add an IP header and pretend it's a broadcast packet
ih = (struct iphdr*)skb_push(skb, sizeof(struct iphdr));
ih->version = 4;
ih->ihl = 5;
ih->tos = 0;
ih->tot_len = htons(len + sizeof(struct iphdr));
ih->id = 555;
ih->frag_off = 0;
ih->ttl = 64;
ih->protocol = 17;
ih->check = 0x0000;
ih->saddr = 0x00000000L;
ih->daddr = 0xFFFFFFFFL;
skb_reset_network_header(skb);
ih->check = ip_fast_csum((unsigned char *)ih, ih->ihl);
skb->dev = dev;
skb->protocol = ETH_P_IP;
skb->ip_summed = CHECKSUM_UNNECESSARY; // don't check it (does this make any difference?)
packet_stat = netif_rx(skb);
if(packet_stat == NET_RX_SUCCESS) {
printk(KERN_ALERT "[NET] Packet received successfully\n");
} else if(packet_stat == NET_RX_DROP) {
printk(KERN_ALERT "[NET] Packet was dropped!\n");
}
priv->stats.rx_packets++;
priv->stats.rx_bytes += len;
}
/*
* Receive a packet from device and send data to the right place
*/
void xbee_receive_packet(struct net_device *dev, unsigned char *data, int len)
{
struct xbee_priv *priv = netdev_priv(dev);
// printk(KERN_ALERT "[XBEE] receive_packet called ]\n");
switch(*data) {
case ZIGBEE_RECEIVE_PACKET:
printk(KERN_ALERT "[XBEE] Zigbee Receive Packet Frame received\n");
if(len<13) {
printk(KERN_ALERT "[XBEE] Packet too short to be a Receive Packet Frame!\n");
goto out;
}
xbee_rx(dev, (data + 12), len - 12);
goto out;
case ZIGBEE_TRANSMIT_STATUS:
//printk(KERN_ALERT "[XBEE] Zigbee Transmit Status Frame received\n");
if(len != 7) {
printk(KERN_ALERT "[XBEE] Packet is wrong length for a Transmit Status Packet!\n");
goto out;
}
if(data[5] == TRANSMIT_SUCCESS) {
printk(KERN_ALERT "[XBEE] Packet delivery reported as success!\n");
//TODO: report which packet by reading message (and notify super-paranoid drivers?)
} else {
if(data[5] == TRANSMIT_INVALID) {
printk(KERN_ALERT "[XBEE] Transmit failed: invalid endpoint\n");
} else if(data[5] == TRANSMIT_ADDRNOTFOUND) {
printk(KERN_ALERT "[XBEE] Transmit failed: address not found\n");
} else {
printk(KERN_ALERT "[XBEE] Packet delivery failed with status %d\n", data[5]);
}
}
goto out;
case NODE_IDENTIFICATION_INDICATOR:
printk(KERN_ALERT "[XBEE] NODE_IDENTIFICATION_INDICATOR Frame received\n");
break;
case MODEM_STATUS:
printk(KERN_ALERT "[XBEE] Zigbee Modem Status Frame received\n");
break;
case AT_COMMAND:
printk(KERN_ALERT "[XBEE] Zigbee AT_COMMAND Frame received\n");
break;
case AT_COMMAND_QUEUE_PARAMETER_VALUE:
printk(KERN_ALERT "[XBEE] AT_COMMAND_QUEUE_PARAMETER_VALUE Frame received\n");
break;
case AT_COMMAND_RESPONSE:
printk(KERN_ALERT "[XBEE] AT_COMMAND_RESPONSE Frame received\n");
break;
case REMOTE_COMMAND_REQUEST:
printk(KERN_ALERT "[XBEE] REMOTE_COMMAND_REQUEST Frame received\n");
break;
case REMOTE_COMMAND_RESPONSE:
printk(KERN_ALERT "[XBEE] REMOTE_COMMAND_RESPONSE Frame received\n");
break;
case ZIGBEE_TRANSMIT_REQUEST:
printk(KERN_ALERT "[XBEE] ZIGBEE_TRANSMIT_REQUEST Frame received\n");
break;
case EXPLICIT_ADDRESSING_COMMAND_FRAME:
printk(KERN_ALERT "[XBEE] EXPLICIT_ADDRESSING_COMMAND_FRAME received\n");
break;
case ZIGBEE_EXPLICIT_RX_INDICATOR:
printk(KERN_ALERT "[XBEE] ZIGBEE_EXPLICIT_RX_INDICATOR Frame received\n");
break;
case ZIGBEE_IO_DATA_SAMPLE_RX_INDICATOR:
printk(KERN_ALERT "[XBEE] ZIGBEE_IO_DATA_SAMPLE_RX_INDICATOR Frame received\n");
break;
case XBEE_SENSOR_READ_INDICATOR:
printk(KERN_ALERT "[XBEE] XBEE_SENSOR_READ_INDICATOR Frame received\n");
break;
default:
printk(KERN_ALERT "[XBEE] UNKNOWN Frame Received : errors %lu\n", priv->stats.rx_dropped++);
}
out:
return;
}
/*
* Adds in the checksum and sends the packet off to the serial driver.
*/
static void xbee_hw_tx(char *frame, int len, struct net_device *dev)
{
int i;
unsigned char checksum;
int actual;
printk(KERN_ALERT "[NET hardware_tx called, %d bytes ]\n", len);
//Add start delimiter
*frame = 0x7E;
//Checksum
checksum = 0;
for(i=3; i<(len-1); i++) {
if(frame[i] == 0x7D) {
i++;
checksum += (unsigned char) frame[i] ^ 0x20;
} else {
checksum += ((unsigned char)frame[i]);
}
}
checksum = 0xFF - checksum;
if (checksum == 0x7E || checksum == 0x7D || checksum == 0x11 || checksum == 0x13) {
frame[len-1] = 0x7D;
frame[len] = checksum ^ 0x20;
len++;
} else {
frame[len-1] = checksum;
}
//Send the data to serial driver
if(main_tty != NULL) {
//printk(KERN_ALERT "Setting DO_WRITE_WAKEUP\n");
main_tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
//printk(KERN_ALERT "Writing the data to tty...\n");
actual = main_tty->driver->ops->write(main_tty, frame, len);
if(actual != len) {
printk(KERN_ALERT "Write failed!\n");
}
} else {
printk(KERN_ALERT "No tty is attached!\n");
}
//printk(KERN_ALERT "Freeing the frame memory\n");
kfree(frame);
}
/*
* Copies bytes from one array into another, escaping them if necessary.
* Returns the size of the new array, including character escapes.
* The destination array MUST be at least twice the size of the source
*/
static int escape_into(char *dest, const void *srcarray, int len) {
int i, j=0;
const char *src = srcarray;
for(i=0; i<len; i++) {
char unesc = *(src + i);
if( unesc == 0x7D || unesc == 0x7E || unesc == 0x11 || unesc == 0x13) {
dest[j] = 0x7D;
dest[j+1] = unesc ^ 0x20;
j+=2;
} else {
dest[j] = unesc;
j++;
}
}
return j;
}
/*
* Called by the networking layers to transmit a new packet.
* Constructs the XBee packet and hands off to xbee_hw_tx to do
* the checksum and serial transmission.
*/
int xbee_tx(struct sk_buff *skb, struct net_device *dev)
{
int framelen, datalen;
char *frame;
struct udphdr *udp_header;
struct xbee_priv *priv = netdev_priv(dev);
struct xbee_tx_header header = {
.length = 0x00,
.api_id = 0x10,
.frame_id = 0x01,
.radius = 0x00,
.options = 0x00
};
if(main_tty == NULL) {
printk(KERN_ALERT "No tty attached!\nMake sure ldisc_daemon is running\n");
return 0;
}
//printk(KERN_ALERT "[NET tx called, %d bytes in sk_buff]\n", skb->len);
/* If this is a non-UDP/IP packet, drop it
Also needs to have the XBee HW address in first 8 bytes */
if(skb->len < (sizeof(struct iphdr) + sizeof(struct udphdr) + 8)) {
printk(KERN_ALERT "ERROR: Packet is too short to be TURK protocol!\n");
return 0;
}
header.address = cpu_to_be64(*((u64*)(skb->data + PACKET_ADDR_OFFSET)));
header.net_address = cpu_to_be16(0xFFFE);
header.length = cpu_to_be16(skb->len - PACKET_DATA_OFFSET + 6);
datalen = skb->len - PACKET_ADDR_OFFSET - 8;
// Allocate buffer to hold entire serial frame, including start byte and checksum
frame = kmalloc(sizeof(struct xbee_tx_header) + (2*datalen) + 2, GFP_KERNEL);
/* Assemble the frame */
/* Escaping the XBee header */
//printk(KERN_ALERT "Adding XBee header- length is %u\n", sizeof(header) + 1);
framelen = 1 + escape_into((frame + 1), &header, sizeof(header));
/* Escaping the UDP header */
// First fix the length field - the packet is now 8 bytes shorter
udp_header = (struct udphdr *)(skb->data + PACKET_DATA_OFFSET);
udp_header->len = cpu_to_be16(be16_to_cpu(udp_header->len) - 8);
//printk(KERN_ALERT "Adding UDP header - length is %u\n", sizeof(struct udphdr));
framelen += escape_into((frame + framelen), (skb->data + PACKET_DATA_OFFSET), sizeof(struct udphdr));
/* Escaping the data (not including the hardware address */
//printk(KERN_ALERT "Adding data - length is %u\n", datalen);
framelen += escape_into((frame + framelen), (skb->data + PACKET_ADDR_OFFSET + 8), datalen);
framelen++;
/* save the timestamp */
dev->trans_start = jiffies;
//Stop the interface from sending more data, get the spinlock, and send it!
netif_stop_queue(dev);
spin_lock(&priv->lock);
xbee_hw_tx(frame, framelen, dev);
//Free the skbuff, we've copied all the data out
dev_kfree_skb(skb);
spin_unlock(&priv->lock);
return 0;
}
/*
* Ioctl commands
*/
int xbee_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
printk(KERN_ALERT "[NET ioctl called, command is %u ]\n", cmd);
return 0;
}
/*
* Return statistics to the caller
*/
struct net_device_stats *xbee_stats(struct net_device *dev)
{
struct xbee_priv *priv = netdev_priv(dev);
//printk(KERN_ALERT "[NET device_stats called ]\n");
return &priv->stats;
}
/*
* Change the MAC address
*/
static int xbee_mac_addr(struct net_device *dev, void *p) {
struct sockaddr *addr = p;
//printk(KERN_ALERT "[NET mac_addr called ]\n");
if (netif_running(dev))
return -EBUSY;
//TODO: Check if it's a valid address ...somehow...
memcpy(dev->dev_addr, addr->sa_data, 8);
return 0;
}
static int xbee_validate_addr(struct net_device *dev) {
// printk(KERN_ALERT "[NET validate_addr called, addr_len=%u\n", dev->addr_len);
return 0;
}
/*
* Initialize the net_device structure
*/
void xbee_init(struct net_device *dev)
{
struct xbee_priv *priv;
dev->set_mac_address = xbee_mac_addr;
dev->validate_addr = xbee_validate_addr;
dev->mtu = XBEE_DATA_MTU;
dev->addr_len = 8;
dev->tx_queue_len = 1000;
memset(dev->broadcast, 0xFF, 8);
dev->open = xbee_open;
dev->stop = xbee_release;
dev->hard_start_xmit = xbee_tx;
dev->do_ioctl = xbee_ioctl;
dev->get_stats = xbee_stats;
#ifdef XBEE_CHECK_TRANSMIT
dev->tx_timeout = xbee_tx_timeout;
dev->watchdog_timeo = 20*HZ;
#endif
/* keep the default flags, just add NOARP */
dev->flags |= IFF_NOARP;
dev->features |= NETIF_F_NO_CSUM;
/*
* Then, initialize the priv field. This encloses the statistics
* and a few private fields.
*/
priv = netdev_priv(dev);
memset(priv, 0, sizeof(struct xbee_priv));
spin_lock_init(&priv->lock);
}
/*
***************End Network Functions*************
*/
/*
***************LDISC Functions*************
*/
/*
* The following routines are called from above (user space/tty).
*/
static int n_xbee_open(struct tty_struct *tty) {
struct xbee_priv *priv = netdev_priv(xbee_dev);
//printk(KERN_ALERT "OPEN CALLED\n");
// Don't allow more than one tty to be attached
if( main_tty != NULL )
return -EPERM;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
main_tty = tty;
printk(KERN_ALERT "Attached to a tty!\n\n");
priv->rbuff = kmalloc(XBEE_MAXFRAME, GFP_KERNEL);
priv->rcount = 0;
priv->frame_status = UNFRAMED;
priv->frame_len = 0;
return 0;
}
static void n_xbee_close(struct tty_struct *tty) {
struct xbee_priv *priv = netdev_priv(xbee_dev);
printk(KERN_ALERT "CLOSE CALLED\n");
module_put(THIS_MODULE);
main_tty = NULL;
kfree(priv->rbuff);
}
static void n_xbee_flush_buffer(struct tty_struct *tty) {
//printk(KERN_ALERT "FLUSH_BUFFER CALLED\n");
}
static ssize_t n_xbee_chars_in_buffer(struct tty_struct *tty) {
//printk(KERN_ALERT "CHARS_IN_BUFFER CALLED\n");
return 0;
}
static int n_xbee_ioctl(struct tty_struct * tty, struct file * file, unsigned int cmd, unsigned long arg) {
printk(KERN_ALERT "IOCTL CALLED\n");
return -EPERM;
}
static unsigned int n_xbee_poll(struct tty_struct *tty, struct file *file, struct poll_table_struct *poll) {
printk(KERN_ALERT "POLL CALLED\n");
return 0;
}
/*
* The following routines are called from below (serial port driver).
*/
static char checksum_validate(unsigned char *buffer, int len, unsigned char checksum) {
int i = 0;
while(len--) {
checksum += buffer[i++];
}
if(checksum == 0xFF)
return true;
printk(KERN_ALERT "[XBEE] CSUM should be 0xFF, is 0x%x\n", checksum);
return false;
}
/*
* Called from the serial driver when new received data is ready
*/
static void n_xbee_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) {
unsigned char temp;
struct xbee_priv *priv = netdev_priv(xbee_dev);
unsigned char checksum;
printk(KERN_ALERT "[XBEE] RECEIVE_BUF CALLED %d chars received\n", count);
while(count--) {
temp = *cp++;
//Escape characters after 0x7D byte
if(temp == 0x7D) {
temp = (*cp++) ^ 0x20;
}
//Start a new frame if 0x7E received, even if we seem to be in the middle of one
if(temp == 0x7E) {
priv->frame_status = FRAME_LEN_HIGH;
priv->frame_len = 0;
priv->rcount = 0;
continue;
}
switch(priv->frame_status) {
//FIXME: All the Xbee packets seem to have two extra bytes on the end. why...?
case UNFRAMED:
//printk(KERN_ALERT "Unframed data received: 0x%x\n", temp);
break;
case FRAME_LEN_HIGH:
priv->frame_len = (temp) << 8;
priv->frame_status = FRAME_LEN_LOW;
break;
case FRAME_LEN_LOW:
priv->frame_len |= (temp);
priv->frame_status = FRAME_DATA;
priv->rcount = 0;
break;
case FRAME_DATA:
//Add to the frame buffer
priv->rbuff[priv->rcount++] = (temp);
//Is the frame done?
if(priv->rcount == (priv->frame_len)) {
priv->frame_status = FRAME_CHECKSUM;
}
//Is the frame FUBAR?
if(priv->rcount > XBEE_MAXFRAME || priv->rcount > priv->frame_len || priv->frame_len > XBEE_MAXFRAME) {
priv->rcount = 0;
priv->frame_status = UNFRAMED;
printk(KERN_ALERT "[XBEE] A frame got pwned!! : %lu errors\n", priv->stats.rx_dropped++);
}
break;
case FRAME_CHECKSUM:
checksum = temp;
if(checksum_validate(priv->rbuff, priv->frame_len, checksum)) {
//Hand off to xbee_receive_packet for networking/packet ID
xbee_receive_packet(xbee_dev, priv->rbuff, priv->frame_len);
} else {
printk(KERN_ALERT "[XBEE] CHECKSUM FAIL : %lu errors\n", priv->stats.rx_dropped++);
}
priv->frame_status = UNFRAMED;
priv->frame_len = 0;
priv->rcount = 0;
break;
default:
printk(KERN_ALERT "[XBEE] WARNING - Undefined Frame Status!!\n");
priv->frame_status = UNFRAMED;
}
}
}
static void n_xbee_write_wakeup(struct tty_struct *tty) {
main_tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
netif_wake_queue(xbee_dev);
}
struct tty_ldisc_ops n_xbee_ldisc = {
.owner = THIS_MODULE,
.magic = TTY_LDISC_MAGIC,
.name = "n_xbee",
.open = n_xbee_open, /* TTY */
.close = n_xbee_close, /* TTY */
.flush_buffer = n_xbee_flush_buffer, /* TTY */
.chars_in_buffer = n_xbee_chars_in_buffer, /* TTY */
.read = NULL, /* TTY */
.write = NULL, /* TTY */
.ioctl = n_xbee_ioctl, /* TTY */
.set_termios = NULL, /* FIXME no support for termios setting yet */
.poll = n_xbee_poll,
.receive_buf = n_xbee_receive_buf, /* Serial driver */
.write_wakeup = n_xbee_write_wakeup /* Serial driver */
};
/*
*************** End of LDISC Functions*************
*/
void xbee_cleanup(void)
{
if (xbee_dev) {
unregister_netdev(xbee_dev);
free_netdev(xbee_dev);
}
return;
}
int xbee_init_module(void)
{
int result, ret=0;
//Register the line discipline
// TODO: actually use a well-known discipline instead of over-riding
// a relatively pointless one (N_SLCAN?)
result = tty_register_ldisc(N_XBEE, &n_xbee_ldisc);
if(result) {
printk(KERN_ALERT "Registering the line discipline failed with error %d\n", result);
return result;
}
/* Allocate the devices */
xbee_dev = alloc_netdev(sizeof(struct xbee_priv), "xbee%d",
xbee_init);
if (xbee_dev == NULL)
goto out;
ret = -ENODEV;
if ((result = register_netdev(xbee_dev)))
printk("xbee: error %i registering device \"%s\"\n", result, xbee_dev->name);
else
ret = 0;
out:
if (ret)
xbee_cleanup();
return ret;
}
module_init(xbee_init_module);
module_exit(xbee_cleanup);
MODULE_LICENSE("GPL");