12 #include <linux/errno.h>
13 #include <linux/hdlc.h>
14 #include <linux/if_arp.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/poll.h>
22 #include <linux/slab.h>
27 #define DEBUG_HARD_HEADER 0
29 #define HDLC_ADDR_ALLSTATIONS 0xFF
30 #define HDLC_CTRL_UI 0x03
32 #define PID_LCP 0xC021
34 #define PID_IPCP 0x8021
35 #define PID_IPV6 0x0057
36 #define PID_IPV6CP 0x8057
43 static const char *
const code_names[
CP_CODES] = {
44 "0",
"ConfReq",
"ConfAck",
"ConfNak",
"ConfRej",
"TermReq",
45 "TermAck",
"CodeRej",
"ProtoRej",
"EchoReq",
"EchoReply",
"Discard"
87 enum {
START = 0,
STOP,
TO_GOOD,
TO_BAD,
RCR_GOOD,
RCR_BAD,
RCA,
RCN,
RTR,
RTA,
93 static const char *
const state_names[
STATES] = {
94 "Closed",
"Stopped",
"Stopping",
"ReqSent",
"AckRecv",
"AckSent",
97 static const char *
const event_names[
EVENTS] = {
98 "Start",
"Stop",
"TO+",
"TO-",
"RCR+",
"RCR-",
"RCA",
"RCN",
99 "RTR",
"RTA",
"RUC",
"RXJ+",
"RXJ-"
109 return (
struct ppp *)dev_to_hdlc(dev)->state;
114 struct ppp *
ppp = get_ppp(dev);
128 static inline const char* proto_name(
u16 pid)
172 #if DEBUG_HARD_HEADER
200 static void ppp_tx_flush(
void)
208 u8 id,
unsigned int len,
const void *data)
212 unsigned int magic_len = 0;
221 magic_len =
sizeof(
magic);
224 sizeof(
struct cp_header) + magic_len + len);
226 netdev_warn(dev,
"out of memory in ppp_tx_cp()\n");
245 for (i = 0; i <
min_t(
unsigned int, magic_len + len,
DEBUG_CP); i++) {
253 ppp_hard_header(skb, dev, pid,
NULL,
NULL, 0);
257 skb_reset_network_header(skb);
285 {
INV , 0 , 0 , 0 , 0 , 0 , 0 },
287 {
INV ,
INV , 1 , 1 , 1 , 1 , INV },
293 { 0 , 1 , 1 , 3 , 3 , 5 ,
SCR|3 },
295 { 0 , 1 , 2 , 3 , 3 , 5 , 6 },
296 { 0 , 1 , 1 , 1 , 1 , 1 ,
IRC|
STR|2},
305 u8 id,
unsigned int len,
const void *data)
308 struct ppp *ppp = get_ppp(dev);
311 old_state = proto->
state;
317 proto_name(pid), event_names[event], state_names[proto->
state]);
320 action = cp_table[
event][old_state];
338 ppp_tx_cp(dev, pid, code,
id, len, data);
347 netdev_info(dev,
"%s up\n", proto_name(pid));
349 netif_dormant_off(dev);
358 netdev_info(dev,
"%s down\n", proto_name(pid));
360 netif_dormant_on(dev);
370 proto_name(pid), event_names[event], state_names[proto->
state]);
381 unsigned int len =
req_len, nak_len = 0, rej_len = 0;
384 dev->
stats.rx_dropped++;
388 for (opt = data; len; len -= opt[1], opt += opt[1]) {
389 if (len < 2 || len < opt[1]) {
390 dev->
stats.rx_errors++;
401 if (!
memcmp(opt, valid_accm,
405 memcpy(out + nak_len, valid_accm,
407 nak_len +=
sizeof(valid_accm);
412 if (opt[1] != 6 || (!opt[2] && !opt[3] &&
418 memcpy(out + rej_len, opt, opt[1]);
432 static int ppp_rx(
struct sk_buff *skb)
436 struct ppp *ppp = get_ppp(dev);
457 proto = get_proto(dev, pid);
495 ppp_cp_event(dev, pid,
RXJ_BAD, 0, 0,
502 cp->
id, len - 4, skb->
data + 4);
517 ppp_cp_parse_cr(dev, pid, cp->
id, len, skb->
data);
522 ppp_cp_event(dev, pid,
RCA, 0, 0, 0,
NULL);
528 ppp_cp_event(dev, pid,
RCN, 0, 0, 0,
NULL);
532 ppp_cp_event(dev, pid,
RTR, 0, cp->
id, 0,
NULL);
536 ppp_cp_event(dev, pid,
RTA, 0, 0, 0,
NULL);
547 ppp_cp_event(dev, pid,
RUC, 0, 0, len, cp);
553 dev->
stats.rx_errors++;
555 spin_unlock_irqrestore(&ppp->
lock, flags);
561 static void ppp_timer(
unsigned long arg)
563 struct proto *proto = (
struct proto *)arg;
564 struct ppp *ppp = get_ppp(proto->
dev);
568 switch (proto->
state) {
587 netdev_info(proto->
dev,
"Link down\n");
600 spin_unlock_irqrestore(&ppp->
lock, flags);
607 struct ppp *ppp = get_ppp(dev);
611 struct proto *proto = &ppp->
protos[
i];
614 proto->
timer.function = ppp_timer;
615 proto->
timer.data = (
unsigned long)proto;
639 .type_trans = ppp_type_trans,
645 static const struct header_ops ppp_header_ops = {
646 .create = ppp_hard_header,
655 switch (ifr->ifr_settings.type) {
657 if (dev_to_hdlc(dev)->proto != &proto)
690 netif_dormant_on(dev);
698 static int __init mod_init(
void)
705 static void __exit mod_exit(
void)