Commit a134be24 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by David S. Miller

o LAPB: use refcounts and rwlock to protect lapb_cb and list

Also some CodingStyle code reformatting.
Ah, killed the typedef for lapb_cb.
parent 2150b1f5
...@@ -78,8 +78,8 @@ struct lapb_frame { ...@@ -78,8 +78,8 @@ struct lapb_frame {
/* /*
* The per LAPB connection control structure. * The per LAPB connection control structure.
*/ */
typedef struct lapb_cb { struct lapb_cb {
struct lapb_cb *next; struct list_head node;
void *token; void *token;
/* Link status fields */ /* Link status fields */
...@@ -100,43 +100,45 @@ typedef struct lapb_cb { ...@@ -100,43 +100,45 @@ typedef struct lapb_cb {
/* FRMR control information */ /* FRMR control information */
struct lapb_frame frmr_data; struct lapb_frame frmr_data;
unsigned char frmr_type; unsigned char frmr_type;
} lapb_cb;
atomic_t refcnt;
};
/* lapb_iface.c */ /* lapb_iface.c */
extern void lapb_connect_confirmation(lapb_cb *, int); extern void lapb_connect_confirmation(struct lapb_cb *lapb, int);
extern void lapb_connect_indication(lapb_cb *, int); extern void lapb_connect_indication(struct lapb_cb *lapb, int);
extern void lapb_disconnect_confirmation(lapb_cb *, int); extern void lapb_disconnect_confirmation(struct lapb_cb *lapb, int);
extern void lapb_disconnect_indication(lapb_cb *, int); extern void lapb_disconnect_indication(struct lapb_cb *lapb, int);
extern int lapb_data_indication(lapb_cb *, struct sk_buff *); extern int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *);
extern int lapb_data_transmit(lapb_cb *, struct sk_buff *); extern int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *);
/* lapb_in.c */ /* lapb_in.c */
extern void lapb_data_input(lapb_cb *, struct sk_buff *); extern void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *);
/* lapb_out.c */ /* lapb_out.c */
extern void lapb_kick(lapb_cb *); extern void lapb_kick(struct lapb_cb *lapb);
extern void lapb_transmit_buffer(lapb_cb *, struct sk_buff *, int); extern void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *, int);
extern void lapb_establish_data_link(lapb_cb *); extern void lapb_establish_data_link(struct lapb_cb *lapb);
extern void lapb_enquiry_response(lapb_cb *); extern void lapb_enquiry_response(struct lapb_cb *lapb);
extern void lapb_timeout_response(lapb_cb *); extern void lapb_timeout_response(struct lapb_cb *lapb);
extern void lapb_check_iframes_acked(lapb_cb *, unsigned short); extern void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short);
extern void lapb_check_need_response(lapb_cb *, int, int); extern void lapb_check_need_response(struct lapb_cb *lapb, int, int);
/* lapb_subr.c */ /* lapb_subr.c */
extern void lapb_clear_queues(lapb_cb *); extern void lapb_clear_queues(struct lapb_cb *lapb);
extern void lapb_frames_acked(lapb_cb *, unsigned short); extern void lapb_frames_acked(struct lapb_cb *lapb, unsigned short);
extern void lapb_requeue_frames(lapb_cb *); extern void lapb_requeue_frames(struct lapb_cb *lapb);
extern int lapb_validate_nr(lapb_cb *, unsigned short); extern int lapb_validate_nr(struct lapb_cb *lapb, unsigned short);
extern void lapb_decode(lapb_cb *, struct sk_buff *, struct lapb_frame *); extern void lapb_decode(struct lapb_cb *lapb, struct sk_buff *, struct lapb_frame *);
extern void lapb_send_control(lapb_cb *, int, int, int); extern void lapb_send_control(struct lapb_cb *lapb, int, int, int);
extern void lapb_transmit_frmr(lapb_cb *); extern void lapb_transmit_frmr(struct lapb_cb *lapb);
/* lapb_timer.c */ /* lapb_timer.c */
extern void lapb_start_t1timer(lapb_cb *); extern void lapb_start_t1timer(struct lapb_cb *lapb);
extern void lapb_start_t2timer(lapb_cb *); extern void lapb_start_t2timer(struct lapb_cb *lapb);
extern void lapb_stop_t1timer(lapb_cb *); extern void lapb_stop_t1timer(struct lapb_cb *lapb);
extern void lapb_stop_t2timer(lapb_cb *); extern void lapb_stop_t2timer(struct lapb_cb *lapb);
extern int lapb_t1timer_running(lapb_cb *); extern int lapb_t1timer_running(struct lapb_cb *lapb);
/* /*
* Debug levels. * Debug levels.
......
...@@ -39,87 +39,93 @@ ...@@ -39,87 +39,93 @@
#include <linux/init.h> #include <linux/init.h>
#include <net/lapb.h> #include <net/lapb.h>
static lapb_cb *volatile lapb_list /* = NULL initially */; static struct list_head lapb_list = LIST_HEAD_INIT(lapb_list);
static rwlock_t lapb_list_lock = RW_LOCK_UNLOCKED;
/* /*
* Free an allocated lapb control block. This is done to centralise * Free an allocated lapb control block. This is done to centralise
* the MOD count code. * the MOD count code.
*/ */
static void lapb_free_cb(lapb_cb *lapb) static void lapb_free_cb(struct lapb_cb *lapb)
{ {
kfree(lapb); kfree(lapb);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
} }
static __inline__ void lapb_hold(struct lapb_cb *lapb)
{
atomic_inc(&lapb->refcnt);
}
static __inline__ void lapb_put(struct lapb_cb *lapb)
{
if (atomic_dec_and_test(&lapb->refcnt))
lapb_free_cb(lapb);
}
/* /*
* Socket removal during an interrupt is now safe. * Socket removal during an interrupt is now safe.
*/ */
static void lapb_remove_cb(lapb_cb *lapb) static void __lapb_remove_cb(struct lapb_cb *lapb)
{ {
lapb_cb *s; if (lapb->node.next) {
unsigned long flags; list_del(&lapb->node);
lapb_put(lapb);
save_flags(flags); cli();
if ((s = lapb_list) == lapb) {
lapb_list = s->next;
restore_flags(flags);
return;
}
while (s != NULL && s->next != NULL) {
if (s->next == lapb) {
s->next = lapb->next;
restore_flags(flags);
return;
} }
s = s->next;
}
restore_flags(flags);
} }
/* /*
* Add a socket to the bound sockets list. * Add a socket to the bound sockets list.
*/ */
static void lapb_insert_cb(lapb_cb *lapb) static void __lapb_insert_cb(struct lapb_cb *lapb)
{ {
unsigned long flags; list_add(&lapb->node, &lapb_list);
lapb_hold(lapb);
save_flags(flags); cli();
lapb->next = lapb_list;
lapb_list = lapb;
restore_flags(flags);
} }
/* /*
* Convert the integer token used by the device driver into a pointer * Convert the integer token used by the device driver into a pointer
* to a LAPB control structure. * to a LAPB control structure.
*/ */
static lapb_cb *lapb_tokentostruct(void *token) static struct lapb_cb *__lapb_tokentostruct(void *token)
{ {
lapb_cb *lapb; struct list_head *entry;
struct lapb_cb *lapb, *use = NULL;
list_for_each(entry, &lapb_list) {
lapb = list_entry(entry, struct lapb_cb, node);
if (lapb->token == token) {
use = lapb;
break;
}
}
for (lapb = lapb_list; lapb != NULL; lapb = lapb->next) if (use)
if (lapb->token == token) lapb_hold(use);
return lapb;
return NULL; return use;
} }
static struct lapb_cb *lapb_tokentostruct(void *token)
{
struct lapb_cb *rc;
read_lock_bh(&lapb_list_lock);
rc = __lapb_tokentostruct(token);
read_unlock_bh(&lapb_list_lock);
return rc;
}
/* /*
* Create an empty LAPB control block. * Create an empty LAPB control block.
*/ */
static lapb_cb *lapb_create_cb(void) static struct lapb_cb *lapb_create_cb(void)
{ {
lapb_cb *lapb; struct lapb_cb *lapb = kmalloc(sizeof(*lapb), GFP_ATOMIC);
if ((lapb = kmalloc(sizeof(*lapb), GFP_ATOMIC)) == NULL) if (!lapb)
return NULL; goto out;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
...@@ -137,55 +143,73 @@ static lapb_cb *lapb_create_cb(void) ...@@ -137,55 +143,73 @@ static lapb_cb *lapb_create_cb(void)
lapb->mode = LAPB_DEFAULT_MODE; lapb->mode = LAPB_DEFAULT_MODE;
lapb->window = LAPB_DEFAULT_WINDOW; lapb->window = LAPB_DEFAULT_WINDOW;
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
atomic_set(&lapb->refcnt, 1);
out:
return lapb; return lapb;
} }
int lapb_register(void *token, struct lapb_register_struct *callbacks) int lapb_register(void *token, struct lapb_register_struct *callbacks)
{ {
lapb_cb *lapb; struct lapb_cb *lapb;
int rc = LAPB_BADTOKEN;
write_lock_bh(&lapb_list_lock);
if (lapb_tokentostruct(token) != NULL) lapb = __lapb_tokentostruct(token);
return LAPB_BADTOKEN; if (lapb) {
lapb_put(lapb);
goto out;
}
if ((lapb = lapb_create_cb()) == NULL) lapb = lapb_create_cb();
return LAPB_NOMEM; rc = LAPB_NOMEM;
if (!lapb)
goto out;
lapb->token = token; lapb->token = token;
lapb->callbacks = *callbacks; lapb->callbacks = *callbacks;
lapb_insert_cb(lapb); __lapb_insert_cb(lapb);
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
return LAPB_OK; rc = LAPB_OK;
out:
write_unlock_bh(&lapb_list_lock);
return rc;
} }
int lapb_unregister(void *token) int lapb_unregister(void *token)
{ {
lapb_cb *lapb; struct lapb_cb *lapb;
int rc = LAPB_BADTOKEN;
if ((lapb = lapb_tokentostruct(token)) == NULL) write_unlock_bh(&lapb_list_lock);
return LAPB_BADTOKEN; lapb = __lapb_tokentostruct(token);
if (!lapb)
goto out;
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb_clear_queues(lapb); lapb_clear_queues(lapb);
lapb_remove_cb(lapb); __lapb_remove_cb(lapb);
lapb_free_cb(lapb); lapb_put(lapb);
rc = LAPB_OK;
return LAPB_OK; out:
write_unlock_bh(&lapb_list_lock);
return rc;
} }
int lapb_getparms(void *token, struct lapb_parms_struct *parms) int lapb_getparms(void *token, struct lapb_parms_struct *parms)
{ {
lapb_cb *lapb; int rc = LAPB_BADTOKEN;
struct lapb_cb *lapb = lapb_tokentostruct(token);
if ((lapb = lapb_tokentostruct(token)) == NULL) if (!lapb)
return LAPB_BADTOKEN; goto out;
parms->t1 = lapb->t1 / HZ; parms->t1 = lapb->t1 / HZ;
parms->t2 = lapb->t2 / HZ; parms->t2 = lapb->t2 / HZ;
...@@ -205,33 +229,29 @@ int lapb_getparms(void *token, struct lapb_parms_struct *parms) ...@@ -205,33 +229,29 @@ int lapb_getparms(void *token, struct lapb_parms_struct *parms)
else else
parms->t2timer = (lapb->t2timer.expires - jiffies) / HZ; parms->t2timer = (lapb->t2timer.expires - jiffies) / HZ;
return LAPB_OK; lapb_put(lapb);
rc = LAPB_OK;
out:
return rc;
} }
int lapb_setparms(void *token, struct lapb_parms_struct *parms) int lapb_setparms(void *token, struct lapb_parms_struct *parms)
{ {
lapb_cb *lapb; int rc = LAPB_BADTOKEN;
struct lapb_cb *lapb = lapb_tokentostruct(token);
if ((lapb = lapb_tokentostruct(token)) == NULL)
return LAPB_BADTOKEN;
if (parms->t1 < 1) if (!lapb)
return LAPB_INVALUE; goto out;
if (parms->t2 < 1) rc = LAPB_INVALUE;
return LAPB_INVALUE; if (parms->t1 < 1 || parms->t2 < 1 || parms->n2 < 1)
goto out_put;
if (parms->n2 < 1)
return LAPB_INVALUE;
if (lapb->state == LAPB_STATE_0) { if (lapb->state == LAPB_STATE_0) {
if (parms->mode & LAPB_EXTENDED) { if (((parms->mode & LAPB_EXTENDED) &&
if (parms->window < 1 || parms->window > 127) (parms->window < 1 || parms->window > 127)) ||
return LAPB_INVALUE; (parms->window < 1 || parms->window > 7))
} else { goto out_put;
if (parms->window < 1 || parms->window > 7)
return LAPB_INVALUE;
}
lapb->mode = parms->mode; lapb->mode = parms->mode;
lapb->window = parms->window; lapb->window = parms->window;
...@@ -241,45 +261,55 @@ int lapb_setparms(void *token, struct lapb_parms_struct *parms) ...@@ -241,45 +261,55 @@ int lapb_setparms(void *token, struct lapb_parms_struct *parms)
lapb->t2 = parms->t2 * HZ; lapb->t2 = parms->t2 * HZ;
lapb->n2 = parms->n2; lapb->n2 = parms->n2;
return LAPB_OK; rc = LAPB_OK;
out_put:
lapb_put(lapb);
out:
return rc;
} }
int lapb_connect_request(void *token) int lapb_connect_request(void *token)
{ {
lapb_cb *lapb; struct lapb_cb *lapb = lapb_tokentostruct(token);
int rc = LAPB_BADTOKEN;
if ((lapb = lapb_tokentostruct(token)) == NULL) if (!lapb)
return LAPB_BADTOKEN; goto out;
switch (lapb->state) { rc = LAPB_OK;
case LAPB_STATE_1: if (lapb->state == LAPB_STATE_1)
return LAPB_OK; goto out_put;
case LAPB_STATE_3:
case LAPB_STATE_4: rc = LAPB_CONNECTED;
return LAPB_CONNECTED; if (lapb->state == LAPB_STATE_3 || lapb->state == LAPB_STATE_4)
} goto out_put;
lapb_establish_data_link(lapb); lapb_establish_data_link(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S0 -> S1\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S0 -> S1\n", lapb->token);
#endif #endif
lapb->state = LAPB_STATE_1; lapb->state = LAPB_STATE_1;
return LAPB_OK; rc = LAPB_OK;
out_put:
lapb_put(lapb);
out:
return rc;
} }
int lapb_disconnect_request(void *token) int lapb_disconnect_request(void *token)
{ {
lapb_cb *lapb; struct lapb_cb *lapb = lapb_tokentostruct(token);
int rc = LAPB_BADTOKEN;
if ((lapb = lapb_tokentostruct(token)) == NULL) if (!lapb)
return LAPB_BADTOKEN; goto out;
switch (lapb->state) { switch (lapb->state) {
case LAPB_STATE_0: case LAPB_STATE_0:
return LAPB_NOTCONNECTED; rc = LAPB_NOTCONNECTED;
goto out_put;
case LAPB_STATE_1: case LAPB_STATE_1:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
...@@ -291,10 +321,12 @@ int lapb_disconnect_request(void *token) ...@@ -291,10 +321,12 @@ int lapb_disconnect_request(void *token)
lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND); lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
return LAPB_NOTCONNECTED; rc = LAPB_NOTCONNECTED;
goto out_put;
case LAPB_STATE_2: case LAPB_STATE_2:
return LAPB_OK; rc = LAPB_OK;
goto out_put;
} }
lapb_clear_queues(lapb); lapb_clear_queues(lapb);
...@@ -311,77 +343,87 @@ int lapb_disconnect_request(void *token) ...@@ -311,77 +343,87 @@ int lapb_disconnect_request(void *token)
printk(KERN_DEBUG "lapb: (%p) S3 -> S2\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S2\n", lapb->token);
#endif #endif
return LAPB_OK; rc = LAPB_OK;
out_put:
lapb_put(lapb);
out:
return rc;
} }
int lapb_data_request(void *token, struct sk_buff *skb) int lapb_data_request(void *token, struct sk_buff *skb)
{ {
lapb_cb *lapb; struct lapb_cb *lapb = lapb_tokentostruct(token);
int rc = LAPB_BADTOKEN;
if ((lapb = lapb_tokentostruct(token)) == NULL) if (!lapb)
return LAPB_BADTOKEN; goto out;
rc = LAPB_NOTCONNECTED;
if (lapb->state != LAPB_STATE_3 && lapb->state != LAPB_STATE_4) if (lapb->state != LAPB_STATE_3 && lapb->state != LAPB_STATE_4)
return LAPB_NOTCONNECTED; goto out_put;
skb_queue_tail(&lapb->write_queue, skb); skb_queue_tail(&lapb->write_queue, skb);
lapb_kick(lapb); lapb_kick(lapb);
rc = LAPB_OK;
return LAPB_OK; out_put:
lapb_put(lapb);
out:
return rc;
} }
int lapb_data_received(void *token, struct sk_buff *skb) int lapb_data_received(void *token, struct sk_buff *skb)
{ {
lapb_cb *lapb; struct lapb_cb *lapb = lapb_tokentostruct(token);
int rc = LAPB_BADTOKEN;
if ((lapb = lapb_tokentostruct(token)) == NULL)
return LAPB_BADTOKEN;
if (lapb) {
lapb_data_input(lapb, skb); lapb_data_input(lapb, skb);
lapb_put(lapb);
rc = LAPB_OK;
}
return LAPB_OK; return rc;
} }
void lapb_connect_confirmation(lapb_cb *lapb, int reason) void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
{ {
if (lapb->callbacks.connect_confirmation != NULL) if (lapb->callbacks.connect_confirmation)
(lapb->callbacks.connect_confirmation)(lapb->token, reason); lapb->callbacks.connect_confirmation(lapb->token, reason);
} }
void lapb_connect_indication(lapb_cb *lapb, int reason) void lapb_connect_indication(struct lapb_cb *lapb, int reason)
{ {
if (lapb->callbacks.connect_indication != NULL) if (lapb->callbacks.connect_indication)
(lapb->callbacks.connect_indication)(lapb->token, reason); lapb->callbacks.connect_indication(lapb->token, reason);
} }
void lapb_disconnect_confirmation(lapb_cb *lapb, int reason) void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
{ {
if (lapb->callbacks.disconnect_confirmation != NULL) if (lapb->callbacks.disconnect_confirmation)
(lapb->callbacks.disconnect_confirmation)(lapb->token, reason); lapb->callbacks.disconnect_confirmation(lapb->token, reason);
} }
void lapb_disconnect_indication(lapb_cb *lapb, int reason) void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
{ {
if (lapb->callbacks.disconnect_indication != NULL) if (lapb->callbacks.disconnect_indication)
(lapb->callbacks.disconnect_indication)(lapb->token, reason); lapb->callbacks.disconnect_indication(lapb->token, reason);
} }
int lapb_data_indication(lapb_cb *lapb, struct sk_buff *skb) int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
{ {
if (lapb->callbacks.data_indication != NULL) { if (lapb->callbacks.data_indication)
return (lapb->callbacks.data_indication)(lapb->token, skb); return lapb->callbacks.data_indication(lapb->token, skb);
}
kfree_skb(skb); kfree_skb(skb);
return NET_RX_CN_HIGH; /* For now; must be != NET_RX_DROP */ return NET_RX_CN_HIGH; /* For now; must be != NET_RX_DROP */
} }
int lapb_data_transmit(lapb_cb *lapb, struct sk_buff *skb) int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
{ {
int used = 0; int used = 0;
if (lapb->callbacks.data_transmit != NULL) { if (lapb->callbacks.data_transmit) {
(lapb->callbacks.data_transmit)(lapb->token, skb); lapb->callbacks.data_transmit(lapb->token, skb);
used = 1; used = 1;
} }
......
...@@ -40,26 +40,33 @@ ...@@ -40,26 +40,33 @@
* State machine for state 0, Disconnected State. * State machine for state 0, Disconnected State.
* The handling of the timer(s) is in file lapb_timer.c. * The handling of the timer(s) is in file lapb_timer.c.
*/ */
static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) static void lapb_state0_machine(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
switch (frame->type) { switch (frame->type) {
case LAPB_SABM: case LAPB_SABM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 RX SABM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 RX SABM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n",
lapb->token);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->state = LAPB_STATE_3; lapb->state = LAPB_STATE_3;
...@@ -74,16 +81,20 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -74,16 +81,20 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_SABME: case LAPB_SABME:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 RX SABME(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 RX SABME(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n",
lapb->token);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->state = LAPB_STATE_3; lapb->state = LAPB_STATE_3;
...@@ -95,18 +106,23 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -95,18 +106,23 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb_connect_indication(lapb, LAPB_OK); lapb_connect_indication(lapb, LAPB_OK);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} }
break; break;
case LAPB_DISC: case LAPB_DISC:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S0 RX DISC(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S0 RX DISC(%d)\n",
printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n", lapb->token, frame->pf); lapb->token, frame->pf);
printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
break; break;
default: default:
...@@ -120,58 +136,74 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -120,58 +136,74 @@ static void lapb_state0_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
* State machine for state 1, Awaiting Connection State. * State machine for state 1, Awaiting Connection State.
* The handling of the timer(s) is in file lapb_timer.c. * The handling of the timer(s) is in file lapb_timer.c.
*/ */
static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) static void lapb_state1_machine(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
switch (frame->type) { switch (frame->type) {
case LAPB_SABM: case LAPB_SABM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 RX SABM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 RX SABM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
} }
break; break;
case LAPB_SABME: case LAPB_SABME:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 RX SABME(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 RX SABME(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} }
break; break;
case LAPB_DISC: case LAPB_DISC:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 RX DISC(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 RX DISC(%d)\n",
printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n", lapb->token, frame->pf); lapb->token, frame->pf);
printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
break; break;
case LAPB_UA: case LAPB_UA:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 RX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 RX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (frame->pf) { if (frame->pf) {
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S1 -> S3\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S1 -> S3\n",
lapb->token);
#endif #endif
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
...@@ -187,11 +219,13 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -187,11 +219,13 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_DM: case LAPB_DM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S1 RX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S1 RX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (frame->pf) { if (frame->pf) {
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n",
lapb->token);
#endif #endif
lapb_clear_queues(lapb); lapb_clear_queues(lapb);
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
...@@ -200,9 +234,6 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -200,9 +234,6 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb_disconnect_indication(lapb, LAPB_REFUSED); lapb_disconnect_indication(lapb, LAPB_REFUSED);
} }
break; break;
default:
break;
} }
kfree_skb(skb); kfree_skb(skb);
...@@ -212,33 +243,42 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -212,33 +243,42 @@ static void lapb_state1_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
* State machine for state 2, Awaiting Release State. * State machine for state 2, Awaiting Release State.
* The handling of the timer(s) is in file lapb_timer.c * The handling of the timer(s) is in file lapb_timer.c
*/ */
static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) static void lapb_state2_machine(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
switch (frame->type) { switch (frame->type) {
case LAPB_SABM: case LAPB_SABM:
case LAPB_SABME: case LAPB_SABME:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S2 RX {SABM,SABME}(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S2 RX {SABM,SABME}(%d)\n",
printk(KERN_DEBUG "lapb: (%p) S2 TX DM(%d)\n", lapb->token, frame->pf); lapb->token, frame->pf);
printk(KERN_DEBUG "lapb: (%p) S2 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
break; break;
case LAPB_DISC: case LAPB_DISC:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S2 RX DISC(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S2 RX DISC(%d)\n",
printk(KERN_DEBUG "lapb: (%p) S2 TX UA(%d)\n", lapb->token, frame->pf); lapb->token, frame->pf);
printk(KERN_DEBUG "lapb: (%p) S2 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
break; break;
case LAPB_UA: case LAPB_UA:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S2 RX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S2 RX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (frame->pf) { if (frame->pf) {
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n",
lapb->token);
#endif #endif
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
...@@ -249,16 +289,19 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -249,16 +289,19 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_DM: case LAPB_DM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (frame->pf) { if (frame->pf) {
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n",
lapb->token);
#endif #endif
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb_disconnect_confirmation(lapb, LAPB_NOTCONNECTED); lapb_disconnect_confirmation(lapb,
LAPB_NOTCONNECTED);
} }
break; break;
...@@ -267,13 +310,14 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -267,13 +310,14 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_RNR: case LAPB_RNR:
case LAPB_RR: case LAPB_RR:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S2 RX {I,REJ,RNR,RR}(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S2 RX {I,REJ,RNR,RR}"
printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n", lapb->token, frame->pf); "(%d)\n", lapb->token, frame->pf);
printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (frame->pf) lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); if (frame->pf)
break; lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
default:
break; break;
} }
...@@ -284,28 +328,33 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -284,28 +328,33 @@ static void lapb_state2_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
* State machine for state 3, Connected State. * State machine for state 3, Connected State.
* The handling of the timer(s) is in file lapb_timer.c * The handling of the timer(s) is in file lapb_timer.c
*/ */
static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) static void lapb_state3_machine(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
int queued = 0; int queued = 0;
int modulus; int modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS :
LAPB_SMODULUS;
modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
switch (frame->type) { switch (frame->type) {
case LAPB_SABM: case LAPB_SABM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX SABM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 RX SABM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->condition = 0x00; lapb->condition = 0x00;
...@@ -319,13 +368,16 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -319,13 +368,16 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_SABME: case LAPB_SABME:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX SABME(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 RX SABME(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->condition = 0x00; lapb->condition = 0x00;
...@@ -336,21 +388,26 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -336,21 +388,26 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb_requeue_frames(lapb); lapb_requeue_frames(lapb);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} }
break; break;
case LAPB_DISC: case LAPB_DISC:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX DISC(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 RX DISC(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n",
lapb->token);
#endif #endif
lapb_clear_queues(lapb); lapb_clear_queues(lapb);
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
...@@ -359,10 +416,12 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -359,10 +416,12 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_DM: case LAPB_DM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 RX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n",
lapb->token);
#endif #endif
lapb_clear_queues(lapb); lapb_clear_queues(lapb);
lapb->state = LAPB_STATE_0; lapb->state = LAPB_STATE_0;
...@@ -373,7 +432,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -373,7 +432,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_RNR: case LAPB_RNR:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX RNR(%d) R%d\n", lapb->token, frame->pf, frame->nr); printk(KERN_DEBUG "lapb: (%p) S3 RX RNR(%d) R%d\n",
lapb->token, frame->pf, frame->nr);
#endif #endif
lapb->condition |= LAPB_PEER_RX_BUSY_CONDITION; lapb->condition |= LAPB_PEER_RX_BUSY_CONDITION;
lapb_check_need_response(lapb, frame->cr, frame->pf); lapb_check_need_response(lapb, frame->cr, frame->pf);
...@@ -384,7 +444,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -384,7 +444,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb->frmr_type = LAPB_FRMR_Z; lapb->frmr_type = LAPB_FRMR_Z;
lapb_transmit_frmr(lapb); lapb_transmit_frmr(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n",
lapb->token);
#endif #endif
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
...@@ -395,7 +456,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -395,7 +456,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_RR: case LAPB_RR:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX RR(%d) R%d\n", lapb->token, frame->pf, frame->nr); printk(KERN_DEBUG "lapb: (%p) S3 RX RR(%d) R%d\n",
lapb->token, frame->pf, frame->nr);
#endif #endif
lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION; lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
lapb_check_need_response(lapb, frame->cr, frame->pf); lapb_check_need_response(lapb, frame->cr, frame->pf);
...@@ -406,7 +468,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -406,7 +468,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb->frmr_type = LAPB_FRMR_Z; lapb->frmr_type = LAPB_FRMR_Z;
lapb_transmit_frmr(lapb); lapb_transmit_frmr(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n",
lapb->token);
#endif #endif
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
...@@ -417,7 +480,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -417,7 +480,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_REJ: case LAPB_REJ:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX REJ(%d) R%d\n", lapb->token, frame->pf, frame->nr); printk(KERN_DEBUG "lapb: (%p) S3 RX REJ(%d) R%d\n",
lapb->token, frame->pf, frame->nr);
#endif #endif
lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION; lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
lapb_check_need_response(lapb, frame->cr, frame->pf); lapb_check_need_response(lapb, frame->cr, frame->pf);
...@@ -431,7 +495,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -431,7 +495,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb->frmr_type = LAPB_FRMR_Z; lapb->frmr_type = LAPB_FRMR_Z;
lapb_transmit_frmr(lapb); lapb_transmit_frmr(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n",
lapb->token);
#endif #endif
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
...@@ -442,14 +507,16 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -442,14 +507,16 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_I: case LAPB_I:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX I(%d) S%d R%d\n", lapb->token, frame->pf, frame->ns, frame->nr); printk(KERN_DEBUG "lapb: (%p) S3 RX I(%d) S%d R%d\n",
lapb->token, frame->pf, frame->ns, frame->nr);
#endif #endif
if (!lapb_validate_nr(lapb, frame->nr)) { if (!lapb_validate_nr(lapb, frame->nr)) {
lapb->frmr_data = *frame; lapb->frmr_data = *frame;
lapb->frmr_type = LAPB_FRMR_Z; lapb->frmr_type = LAPB_FRMR_Z;
lapb_transmit_frmr(lapb); lapb_transmit_frmr(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n",
lapb->token);
#endif #endif
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
...@@ -457,11 +524,11 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -457,11 +524,11 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb->n2count = 0; lapb->n2count = 0;
break; break;
} }
if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) { if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION)
lapb_frames_acked(lapb, frame->nr); lapb_frames_acked(lapb, frame->nr);
} else { else
lapb_check_iframes_acked(lapb, frame->nr); lapb_check_iframes_acked(lapb, frame->nr);
}
if (frame->ns == lapb->vr) { if (frame->ns == lapb->vr) {
int cn; int cn;
cn = lapb_data_indication(lapb, skb); cn = lapb_data_indication(lapb, skb);
...@@ -473,16 +540,18 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -473,16 +540,18 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
* to re-transmit the frame later like * to re-transmit the frame later like
* a frame lost on the wire. * a frame lost on the wire.
*/ */
if(cn == NET_RX_DROP){ if (cn == NET_RX_DROP) {
printk(KERN_DEBUG "LAPB: rx congestion\n"); printk(KERN_DEBUG
"LAPB: rx congestion\n");
break; break;
} }
lapb->vr = (lapb->vr + 1) % modulus; lapb->vr = (lapb->vr + 1) % modulus;
lapb->condition &= ~LAPB_REJECT_CONDITION; lapb->condition &= ~LAPB_REJECT_CONDITION;
if (frame->pf) { if (frame->pf)
lapb_enquiry_response(lapb); lapb_enquiry_response(lapb);
} else { else {
if (!(lapb->condition & LAPB_ACK_PENDING_CONDITION)) { if (!(lapb->condition &
LAPB_ACK_PENDING_CONDITION)) {
lapb->condition |= LAPB_ACK_PENDING_CONDITION; lapb->condition |= LAPB_ACK_PENDING_CONDITION;
lapb_start_t2timer(lapb); lapb_start_t2timer(lapb);
} }
...@@ -493,10 +562,14 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -493,10 +562,14 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb_enquiry_response(lapb); lapb_enquiry_response(lapb);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 TX REJ(%d) R%d\n", lapb->token, frame->pf, lapb->vr); printk(KERN_DEBUG
"lapb: (%p) S3 TX REJ(%d) R%d\n",
lapb->token, frame->pf, lapb->vr);
#endif #endif
lapb->condition |= LAPB_REJECT_CONDITION; lapb->condition |= LAPB_REJECT_CONDITION;
lapb_send_control(lapb, LAPB_REJ, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_REJ,
frame->pf,
LAPB_RESPONSE);
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION; lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
} }
} }
...@@ -504,11 +577,15 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -504,11 +577,15 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_FRMR: case LAPB_FRMR:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX FRMR(%d) %02X %02X %02X %02X %02X\n", lapb->token, frame->pf, skb->data[0], skb->data[1], skb->data[2], skb->data[3], skb->data[4]); printk(KERN_DEBUG "lapb: (%p) S3 RX FRMR(%d) %02X "
"%02X %02X %02X %02X\n", lapb->token, frame->pf,
skb->data[0], skb->data[1], skb->data[2],
skb->data[3], skb->data[4]);
#endif #endif
lapb_establish_data_link(lapb); lapb_establish_data_link(lapb);
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S3 -> S1\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S3 -> S1\n",
lapb->token);
#endif #endif
lapb_requeue_frames(lapb); lapb_requeue_frames(lapb);
lapb->state = LAPB_STATE_1; lapb->state = LAPB_STATE_1;
...@@ -516,7 +593,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -516,7 +593,8 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_ILLEGAL: case LAPB_ILLEGAL:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S3 RX ILLEGAL(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S3 RX ILLEGAL(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb->frmr_data = *frame; lapb->frmr_data = *frame;
lapb->frmr_type = LAPB_FRMR_W; lapb->frmr_type = LAPB_FRMR_W;
...@@ -529,9 +607,6 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -529,9 +607,6 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb->state = LAPB_STATE_4; lapb->state = LAPB_STATE_4;
lapb->n2count = 0; lapb->n2count = 0;
break; break;
default:
break;
} }
if (!queued) if (!queued)
...@@ -542,26 +617,33 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -542,26 +617,33 @@ static void lapb_state3_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
* State machine for state 4, Frame Reject State. * State machine for state 4, Frame Reject State.
* The handling of the timer(s) is in file lapb_timer.c. * The handling of the timer(s) is in file lapb_timer.c.
*/ */
static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) static void lapb_state4_machine(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
switch (frame->type) { switch (frame->type) {
case LAPB_SABM: case LAPB_SABM:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 RX SABM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 RX SABM(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n",
lapb->token);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->state = LAPB_STATE_3; lapb->state = LAPB_STATE_3;
...@@ -576,16 +658,20 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -576,16 +658,20 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
case LAPB_SABME: case LAPB_SABME:
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 RX SABME(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 RX SABME(%d)\n",
lapb->token, frame->pf);
#endif #endif
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
lapb->token, frame->pf);
#endif #endif
#if LAPB_DEBUG > 0 #if LAPB_DEBUG > 0
printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->token); printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n",
lapb->token);
#endif #endif
lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_UA, frame->pf,
LAPB_RESPONSE);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
lapb->state = LAPB_STATE_3; lapb->state = LAPB_STATE_3;
...@@ -597,14 +683,13 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -597,14 +683,13 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
lapb_connect_indication(lapb, LAPB_OK); lapb_connect_indication(lapb, LAPB_OK);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n", lapb->token, frame->pf); printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
lapb->token, frame->pf);
#endif #endif
lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_DM, frame->pf,
LAPB_RESPONSE);
} }
break; break;
default:
break;
} }
kfree_skb(skb); kfree_skb(skb);
...@@ -613,7 +698,7 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_ ...@@ -613,7 +698,7 @@ static void lapb_state4_machine(lapb_cb *lapb, struct sk_buff *skb, struct lapb_
/* /*
* Process an incoming LAPB frame * Process an incoming LAPB frame
*/ */
void lapb_data_input(lapb_cb *lapb, struct sk_buff *skb) void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *skb)
{ {
struct lapb_frame frame; struct lapb_frame frame;
...@@ -621,20 +706,15 @@ void lapb_data_input(lapb_cb *lapb, struct sk_buff *skb) ...@@ -621,20 +706,15 @@ void lapb_data_input(lapb_cb *lapb, struct sk_buff *skb)
switch (lapb->state) { switch (lapb->state) {
case LAPB_STATE_0: case LAPB_STATE_0:
lapb_state0_machine(lapb, skb, &frame); lapb_state0_machine(lapb, skb, &frame); break;
break;
case LAPB_STATE_1: case LAPB_STATE_1:
lapb_state1_machine(lapb, skb, &frame); lapb_state1_machine(lapb, skb, &frame); break;
break;
case LAPB_STATE_2: case LAPB_STATE_2:
lapb_state2_machine(lapb, skb, &frame); lapb_state2_machine(lapb, skb, &frame); break;
break;
case LAPB_STATE_3: case LAPB_STATE_3:
lapb_state3_machine(lapb, skb, &frame); lapb_state3_machine(lapb, skb, &frame); break;
break;
case LAPB_STATE_4: case LAPB_STATE_4:
lapb_state4_machine(lapb, skb, &frame); lapb_state4_machine(lapb, skb, &frame); break;
break;
} }
lapb_kick(lapb); lapb_kick(lapb);
......
...@@ -38,50 +38,48 @@ ...@@ -38,50 +38,48 @@
* This procedure is passed a buffer descriptor for an iframe. It builds * This procedure is passed a buffer descriptor for an iframe. It builds
* the rest of the control part of the frame and then writes it out. * the rest of the control part of the frame and then writes it out.
*/ */
static void lapb_send_iframe(lapb_cb *lapb, struct sk_buff *skb, int poll_bit) static void lapb_send_iframe(struct lapb_cb *lapb, struct sk_buff *skb, int poll_bit)
{ {
unsigned char *frame; unsigned char *frame;
if (skb == NULL) if (!skb)
return; return;
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
frame = skb_push(skb, 2); frame = skb_push(skb, 2);
frame[0] = LAPB_I; frame[0] = LAPB_I;
frame[0] |= (lapb->vs << 1); frame[0] |= lapb->vs << 1;
frame[1] = (poll_bit) ? LAPB_EPF : 0; frame[1] = poll_bit ? LAPB_EPF : 0;
frame[1] |= (lapb->vr << 1); frame[1] |= lapb->vr << 1;
} else { } else {
frame = skb_push(skb, 1); frame = skb_push(skb, 1);
*frame = LAPB_I; *frame = LAPB_I;
*frame |= (poll_bit) ? LAPB_SPF : 0; *frame |= poll_bit ? LAPB_SPF : 0;
*frame |= (lapb->vr << 5); *frame |= lapb->vr << 5;
*frame |= (lapb->vs << 1); *frame |= lapb->vs << 1;
} }
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX I(%d) S%d R%d\n", lapb->token, lapb->state, poll_bit, lapb->vs, lapb->vr); printk(KERN_DEBUG "lapb: (%p) S%d TX I(%d) S%d R%d\n",
lapb->token, lapb->state, poll_bit, lapb->vs, lapb->vr);
#endif #endif
lapb_transmit_buffer(lapb, skb, LAPB_COMMAND); lapb_transmit_buffer(lapb, skb, LAPB_COMMAND);
} }
void lapb_kick(lapb_cb *lapb) void lapb_kick(struct lapb_cb *lapb)
{ {
struct sk_buff *skb, *skbn; struct sk_buff *skb, *skbn;
unsigned short modulus, start, end; unsigned short modulus, start, end;
modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS; modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
start = !skb_peek(&lapb->ack_queue) ? lapb->va : lapb->vs;
start = (skb_peek(&lapb->ack_queue) == NULL) ? lapb->va : lapb->vs;
end = (lapb->va + lapb->window) % modulus; end = (lapb->va + lapb->window) % modulus;
if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) && if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) &&
start != end && start != end && skb_peek(&lapb->write_queue)) {
skb_peek(&lapb->write_queue) != NULL) {
lapb->vs = start; lapb->vs = start;
/* /*
...@@ -95,7 +93,7 @@ void lapb_kick(lapb_cb *lapb) ...@@ -95,7 +93,7 @@ void lapb_kick(lapb_cb *lapb)
break; break;
} }
if (skb->sk != NULL) if (skb->sk)
skb_set_owner_w(skbn, skb->sk); skb_set_owner_w(skbn, skb->sk);
/* /*
...@@ -119,7 +117,7 @@ void lapb_kick(lapb_cb *lapb) ...@@ -119,7 +117,7 @@ void lapb_kick(lapb_cb *lapb)
} }
} }
void lapb_transmit_buffer(lapb_cb *lapb, struct sk_buff *skb, int type) void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *skb, int type)
{ {
unsigned char *ptr; unsigned char *ptr;
...@@ -152,26 +150,30 @@ void lapb_transmit_buffer(lapb_cb *lapb, struct sk_buff *skb, int type) ...@@ -152,26 +150,30 @@ void lapb_transmit_buffer(lapb_cb *lapb, struct sk_buff *skb, int type)
} }
#if LAPB_DEBUG > 2 #if LAPB_DEBUG > 2
printk(KERN_DEBUG "lapb: (%p) S%d TX %02X %02X %02X\n", lapb->token, lapb->state, skb->data[0], skb->data[1], skb->data[2]); printk(KERN_DEBUG "lapb: (%p) S%d TX %02X %02X %02X\n",
lapb->token, lapb->state,
skb->data[0], skb->data[1], skb->data[2]);
#endif #endif
if (!lapb_data_transmit(lapb, skb)) if (!lapb_data_transmit(lapb, skb))
kfree_skb(skb); kfree_skb(skb);
} }
void lapb_establish_data_link(lapb_cb *lapb) void lapb_establish_data_link(struct lapb_cb *lapb)
{ {
lapb->condition = 0x00; lapb->condition = 0x00;
lapb->n2count = 0; lapb->n2count = 0;
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX SABME(1)\n", lapb->token, lapb->state); printk(KERN_DEBUG "lapb: (%p) S%d TX SABME(1)\n",
lapb->token, lapb->state);
#endif #endif
lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND); lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
} else { } else {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX SABM(1)\n", lapb->token, lapb->state); printk(KERN_DEBUG "lapb: (%p) S%d TX SABM(1)\n",
lapb->token, lapb->state);
#endif #endif
lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND); lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
} }
...@@ -180,10 +182,11 @@ void lapb_establish_data_link(lapb_cb *lapb) ...@@ -180,10 +182,11 @@ void lapb_establish_data_link(lapb_cb *lapb)
lapb_stop_t2timer(lapb); lapb_stop_t2timer(lapb);
} }
void lapb_enquiry_response(lapb_cb *lapb) void lapb_enquiry_response(struct lapb_cb *lapb)
{ {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX RR(1) R%d\n", lapb->token, lapb->state, lapb->vr); printk(KERN_DEBUG "lapb: (%p) S%d TX RR(1) R%d\n",
lapb->token, lapb->state, lapb->vr);
#endif #endif
lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
...@@ -191,32 +194,30 @@ void lapb_enquiry_response(lapb_cb *lapb) ...@@ -191,32 +194,30 @@ void lapb_enquiry_response(lapb_cb *lapb)
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION; lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
} }
void lapb_timeout_response(lapb_cb *lapb) void lapb_timeout_response(struct lapb_cb *lapb)
{ {
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX RR(0) R%d\n", lapb->token, lapb->state, lapb->vr); printk(KERN_DEBUG "lapb: (%p) S%d TX RR(0) R%d\n",
lapb->token, lapb->state, lapb->vr);
#endif #endif
lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE); lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE);
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION; lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
} }
void lapb_check_iframes_acked(lapb_cb *lapb, unsigned short nr) void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short nr)
{ {
if (lapb->vs == nr) { if (lapb->vs == nr) {
lapb_frames_acked(lapb, nr); lapb_frames_acked(lapb, nr);
lapb_stop_t1timer(lapb); lapb_stop_t1timer(lapb);
lapb->n2count = 0; lapb->n2count = 0;
} else { } else if (lapb->va != nr) {
if (lapb->va != nr) {
lapb_frames_acked(lapb, nr); lapb_frames_acked(lapb, nr);
lapb_start_t1timer(lapb); lapb_start_t1timer(lapb);
} }
}
} }
void lapb_check_need_response(lapb_cb *lapb, int type, int pf) void lapb_check_need_response(struct lapb_cb *lapb, int type, int pf)
{ {
if (type == LAPB_COMMAND && pf) if (type == LAPB_COMMAND && pf)
lapb_enquiry_response(lapb); lapb_enquiry_response(lapb);
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
/* /*
* This routine purges all the queues of frames. * This routine purges all the queues of frames.
*/ */
void lapb_clear_queues(lapb_cb *lapb) void lapb_clear_queues(struct lapb_cb *lapb)
{ {
skb_queue_purge(&lapb->write_queue); skb_queue_purge(&lapb->write_queue);
skb_queue_purge(&lapb->ack_queue); skb_queue_purge(&lapb->ack_queue);
...@@ -47,7 +47,7 @@ void lapb_clear_queues(lapb_cb *lapb) ...@@ -47,7 +47,7 @@ void lapb_clear_queues(lapb_cb *lapb)
* acknowledged. This replaces the boxes labelled "V(a) <- N(r)" on the * acknowledged. This replaces the boxes labelled "V(a) <- N(r)" on the
* SDL diagram. * SDL diagram.
*/ */
void lapb_frames_acked(lapb_cb *lapb, unsigned short nr) void lapb_frames_acked(struct lapb_cb *lapb, unsigned short nr)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int modulus; int modulus;
...@@ -57,16 +57,15 @@ void lapb_frames_acked(lapb_cb *lapb, unsigned short nr) ...@@ -57,16 +57,15 @@ void lapb_frames_acked(lapb_cb *lapb, unsigned short nr)
/* /*
* Remove all the ack-ed frames from the ack queue. * Remove all the ack-ed frames from the ack queue.
*/ */
if (lapb->va != nr) { if (lapb->va != nr)
while (skb_peek(&lapb->ack_queue) != NULL && lapb->va != nr) { while (skb_peek(&lapb->ack_queue) && lapb->va != nr) {
skb = skb_dequeue(&lapb->ack_queue); skb = skb_dequeue(&lapb->ack_queue);
kfree_skb(skb); kfree_skb(skb);
lapb->va = (lapb->va + 1) % modulus; lapb->va = (lapb->va + 1) % modulus;
} }
}
} }
void lapb_requeue_frames(lapb_cb *lapb) void lapb_requeue_frames(struct lapb_cb *lapb)
{ {
struct sk_buff *skb, *skb_prev = NULL; struct sk_buff *skb, *skb_prev = NULL;
...@@ -76,7 +75,7 @@ void lapb_requeue_frames(lapb_cb *lapb) ...@@ -76,7 +75,7 @@ void lapb_requeue_frames(lapb_cb *lapb)
* possibility of an empty output queue. * possibility of an empty output queue.
*/ */
while ((skb = skb_dequeue(&lapb->ack_queue)) != NULL) { while ((skb = skb_dequeue(&lapb->ack_queue)) != NULL) {
if (skb_prev == NULL) if (!skb_prev)
skb_queue_head(&lapb->write_queue, skb); skb_queue_head(&lapb->write_queue, skb);
else else
skb_append(skb_prev, skb); skb_append(skb_prev, skb);
...@@ -88,7 +87,7 @@ void lapb_requeue_frames(lapb_cb *lapb) ...@@ -88,7 +87,7 @@ void lapb_requeue_frames(lapb_cb *lapb)
* Validate that the value of nr is between va and vs. Return true or * Validate that the value of nr is between va and vs. Return true or
* false for testing. * false for testing.
*/ */
int lapb_validate_nr(lapb_cb *lapb, unsigned short nr) int lapb_validate_nr(struct lapb_cb *lapb, unsigned short nr)
{ {
unsigned short vc = lapb->va; unsigned short vc = lapb->va;
int modulus; int modulus;
...@@ -96,25 +95,27 @@ int lapb_validate_nr(lapb_cb *lapb, unsigned short nr) ...@@ -96,25 +95,27 @@ int lapb_validate_nr(lapb_cb *lapb, unsigned short nr)
modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS; modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
while (vc != lapb->vs) { while (vc != lapb->vs) {
if (nr == vc) return 1; if (nr == vc)
return 1;
vc = (vc + 1) % modulus; vc = (vc + 1) % modulus;
} }
if (nr == lapb->vs) return 1; return nr == lapb->vs;
return 0;
} }
/* /*
* This routine is the centralised routine for parsing the control * This routine is the centralised routine for parsing the control
* information for the different frame formats. * information for the different frame formats.
*/ */
void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) void lapb_decode(struct lapb_cb *lapb, struct sk_buff *skb,
struct lapb_frame *frame)
{ {
frame->type = LAPB_ILLEGAL; frame->type = LAPB_ILLEGAL;
#if LAPB_DEBUG > 2 #if LAPB_DEBUG > 2
printk(KERN_DEBUG "lapb: (%p) S%d RX %02X %02X %02X\n", lapb->token, lapb->state, skb->data[0], skb->data[1], skb->data[2]); printk(KERN_DEBUG "lapb: (%p) S%d RX %02X %02X %02X\n",
lapb->token, lapb->state,
skb->data[0], skb->data[1], skb->data[2]);
#endif #endif
if (lapb->mode & LAPB_MLP) { if (lapb->mode & LAPB_MLP) {
...@@ -146,22 +147,31 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) ...@@ -146,22 +147,31 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame)
skb_pull(skb, 1); skb_pull(skb, 1);
if (lapb->mode & LAPB_EXTENDED) { if (lapb->mode & LAPB_EXTENDED) {
if ((skb->data[0] & LAPB_S) == 0) { if (!(skb->data[0] & LAPB_S)) {
frame->type = LAPB_I; /* I frame - carries NR/NS/PF */ /*
* I frame - carries NR/NS/PF
*/
frame->type = LAPB_I;
frame->ns = (skb->data[0] >> 1) & 0x7F; frame->ns = (skb->data[0] >> 1) & 0x7F;
frame->nr = (skb->data[1] >> 1) & 0x7F; frame->nr = (skb->data[1] >> 1) & 0x7F;
frame->pf = skb->data[1] & LAPB_EPF; frame->pf = skb->data[1] & LAPB_EPF;
frame->control[0] = skb->data[0]; frame->control[0] = skb->data[0];
frame->control[1] = skb->data[1]; frame->control[1] = skb->data[1];
skb_pull(skb, 2); skb_pull(skb, 2);
} else if ((skb->data[0] & LAPB_U) == 1) { /* S frame - take out PF/NR */ } else if ((skb->data[0] & LAPB_U) == 1) {
/*
* S frame - take out PF/NR
*/
frame->type = skb->data[0] & 0x0F; frame->type = skb->data[0] & 0x0F;
frame->nr = (skb->data[1] >> 1) & 0x7F; frame->nr = (skb->data[1] >> 1) & 0x7F;
frame->pf = skb->data[1] & LAPB_EPF; frame->pf = skb->data[1] & LAPB_EPF;
frame->control[0] = skb->data[0]; frame->control[0] = skb->data[0];
frame->control[1] = skb->data[1]; frame->control[1] = skb->data[1];
skb_pull(skb, 2); skb_pull(skb, 2);
} else if ((skb->data[0] & LAPB_U) == 3) { /* U frame - take out PF */ } else if ((skb->data[0] & LAPB_U) == 3) {
/*
* U frame - take out PF
*/
frame->type = skb->data[0] & ~LAPB_SPF; frame->type = skb->data[0] & ~LAPB_SPF;
frame->pf = skb->data[0] & LAPB_SPF; frame->pf = skb->data[0] & LAPB_SPF;
frame->control[0] = skb->data[0]; frame->control[0] = skb->data[0];
...@@ -169,16 +179,25 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) ...@@ -169,16 +179,25 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame)
skb_pull(skb, 1); skb_pull(skb, 1);
} }
} else { } else {
if ((skb->data[0] & LAPB_S) == 0) { if (!(skb->data[0] & LAPB_S)) {
frame->type = LAPB_I; /* I frame - carries NR/NS/PF */ /*
* I frame - carries NR/NS/PF
*/
frame->type = LAPB_I;
frame->ns = (skb->data[0] >> 1) & 0x07; frame->ns = (skb->data[0] >> 1) & 0x07;
frame->nr = (skb->data[0] >> 5) & 0x07; frame->nr = (skb->data[0] >> 5) & 0x07;
frame->pf = skb->data[0] & LAPB_SPF; frame->pf = skb->data[0] & LAPB_SPF;
} else if ((skb->data[0] & LAPB_U) == 1) { /* S frame - take out PF/NR */ } else if ((skb->data[0] & LAPB_U) == 1) {
/*
* S frame - take out PF/NR
*/
frame->type = skb->data[0] & 0x0F; frame->type = skb->data[0] & 0x0F;
frame->nr = (skb->data[0] >> 5) & 0x07; frame->nr = (skb->data[0] >> 5) & 0x07;
frame->pf = skb->data[0] & LAPB_SPF; frame->pf = skb->data[0] & LAPB_SPF;
} else if ((skb->data[0] & LAPB_U) == 3) { /* U frame - take out PF */ } else if ((skb->data[0] & LAPB_U) == 3) {
/*
* U frame - take out PF
*/
frame->type = skb->data[0] & ~LAPB_SPF; frame->type = skb->data[0] & ~LAPB_SPF;
frame->pf = skb->data[0] & LAPB_SPF; frame->pf = skb->data[0] & LAPB_SPF;
} }
...@@ -195,7 +214,8 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame) ...@@ -195,7 +214,8 @@ void lapb_decode(lapb_cb *lapb, struct sk_buff *skb, struct lapb_frame *frame)
* Only supervisory or unnumbered frames are processed, FRMRs are handled * Only supervisory or unnumbered frames are processed, FRMRs are handled
* by lapb_transmit_frmr below. * by lapb_transmit_frmr below.
*/ */
void lapb_send_control(lapb_cb *lapb, int frametype, int poll_bit, int type) void lapb_send_control(struct lapb_cb *lapb, int frametype,
int poll_bit, int type)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned char *dptr; unsigned char *dptr;
...@@ -209,17 +229,17 @@ void lapb_send_control(lapb_cb *lapb, int frametype, int poll_bit, int type) ...@@ -209,17 +229,17 @@ void lapb_send_control(lapb_cb *lapb, int frametype, int poll_bit, int type)
if ((frametype & LAPB_U) == LAPB_U) { if ((frametype & LAPB_U) == LAPB_U) {
dptr = skb_put(skb, 1); dptr = skb_put(skb, 1);
*dptr = frametype; *dptr = frametype;
*dptr |= (poll_bit) ? LAPB_SPF : 0; *dptr |= poll_bit ? LAPB_SPF : 0;
} else { } else {
dptr = skb_put(skb, 2); dptr = skb_put(skb, 2);
dptr[0] = frametype; dptr[0] = frametype;
dptr[1] = (lapb->vr << 1); dptr[1] = (lapb->vr << 1);
dptr[1] |= (poll_bit) ? LAPB_EPF : 0; dptr[1] |= poll_bit ? LAPB_EPF : 0;
} }
} else { } else {
dptr = skb_put(skb, 1); dptr = skb_put(skb, 1);
*dptr = frametype; *dptr = frametype;
*dptr |= (poll_bit) ? LAPB_SPF : 0; *dptr |= poll_bit ? LAPB_SPF : 0;
if ((frametype & LAPB_U) == LAPB_S) /* S frames carry NR */ if ((frametype & LAPB_U) == LAPB_S) /* S frames carry NR */
*dptr |= (lapb->vr << 5); *dptr |= (lapb->vr << 5);
} }
...@@ -231,7 +251,7 @@ void lapb_send_control(lapb_cb *lapb, int frametype, int poll_bit, int type) ...@@ -231,7 +251,7 @@ void lapb_send_control(lapb_cb *lapb, int frametype, int poll_bit, int type)
* This routine generates FRMRs based on information previously stored in * This routine generates FRMRs based on information previously stored in
* the LAPB control block. * the LAPB control block.
*/ */
void lapb_transmit_frmr(lapb_cb *lapb) void lapb_transmit_frmr(struct lapb_cb *lapb)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned char *dptr; unsigned char *dptr;
...@@ -254,7 +274,10 @@ void lapb_transmit_frmr(lapb_cb *lapb) ...@@ -254,7 +274,10 @@ void lapb_transmit_frmr(lapb_cb *lapb)
*dptr++ = lapb->frmr_type; *dptr++ = lapb->frmr_type;
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX FRMR %02X %02X %02X %02X %02X\n", lapb->token, lapb->state, skb->data[1], skb->data[2], skb->data[3], skb->data[4], skb->data[5]); printk(KERN_DEBUG "lapb: (%p) S%d TX FRMR %02X %02X %02X %02X %02X\n",
lapb->token, lapb->state,
skb->data[1], skb->data[2], skb->data[3],
skb->data[4], skb->data[5]);
#endif #endif
} else { } else {
dptr = skb_put(skb, 4); dptr = skb_put(skb, 4);
...@@ -268,7 +291,9 @@ void lapb_transmit_frmr(lapb_cb *lapb) ...@@ -268,7 +291,9 @@ void lapb_transmit_frmr(lapb_cb *lapb)
*dptr++ = lapb->frmr_type; *dptr++ = lapb->frmr_type;
#if LAPB_DEBUG > 1 #if LAPB_DEBUG > 1
printk(KERN_DEBUG "lapb: (%p) S%d TX FRMR %02X %02X %02X\n", lapb->token, lapb->state, skb->data[1], skb->data[2], skb->data[3]); printk(KERN_DEBUG "lapb: (%p) S%d TX FRMR %02X %02X %02X\n",
lapb->token, lapb->state, skb->data[1],
skb->data[2], skb->data[3]);
#endif #endif
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
static void lapb_t1timer_expiry(unsigned long); static void lapb_t1timer_expiry(unsigned long);
static void lapb_t2timer_expiry(unsigned long); static void lapb_t2timer_expiry(unsigned long);
void lapb_start_t1timer(lapb_cb *lapb) void lapb_start_t1timer(struct lapb_cb *lapb)
{ {
del_timer(&lapb->t1timer); del_timer(&lapb->t1timer);
...@@ -48,7 +48,7 @@ void lapb_start_t1timer(lapb_cb *lapb) ...@@ -48,7 +48,7 @@ void lapb_start_t1timer(lapb_cb *lapb)
add_timer(&lapb->t1timer); add_timer(&lapb->t1timer);
} }
void lapb_start_t2timer(lapb_cb *lapb) void lapb_start_t2timer(struct lapb_cb *lapb)
{ {
del_timer(&lapb->t2timer); del_timer(&lapb->t2timer);
...@@ -59,24 +59,24 @@ void lapb_start_t2timer(lapb_cb *lapb) ...@@ -59,24 +59,24 @@ void lapb_start_t2timer(lapb_cb *lapb)
add_timer(&lapb->t2timer); add_timer(&lapb->t2timer);
} }
void lapb_stop_t1timer(lapb_cb *lapb) void lapb_stop_t1timer(struct lapb_cb *lapb)
{ {
del_timer(&lapb->t1timer); del_timer(&lapb->t1timer);
} }
void lapb_stop_t2timer(lapb_cb *lapb) void lapb_stop_t2timer(struct lapb_cb *lapb)
{ {
del_timer(&lapb->t2timer); del_timer(&lapb->t2timer);
} }
int lapb_t1timer_running(lapb_cb *lapb) int lapb_t1timer_running(struct lapb_cb *lapb)
{ {
return timer_pending(&lapb->t1timer); return timer_pending(&lapb->t1timer);
} }
static void lapb_t2timer_expiry(unsigned long param) static void lapb_t2timer_expiry(unsigned long param)
{ {
lapb_cb *lapb = (lapb_cb *)param; struct lapb_cb *lapb = (struct lapb_cb *)param;
if (lapb->condition & LAPB_ACK_PENDING_CONDITION) { if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION; lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
...@@ -86,7 +86,7 @@ static void lapb_t2timer_expiry(unsigned long param) ...@@ -86,7 +86,7 @@ static void lapb_t2timer_expiry(unsigned long param)
static void lapb_t1timer_expiry(unsigned long param) static void lapb_t1timer_expiry(unsigned long param)
{ {
lapb_cb *lapb = (lapb_cb *)param; struct lapb_cb *lapb = (struct lapb_cb *)param;
switch (lapb->state) { switch (lapb->state) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment