6 #include <linux/module.h>
7 #include <linux/wait.h>
8 #include <linux/atmdev.h>
9 #include <linux/atm_tcp.h>
10 #include <linux/bitops.h>
12 #include <linux/slab.h>
13 #include <asm/uaccess.h>
20 #define PRIV(dev) ((struct atmtcp_dev_data *) ((dev)->dev_data))
29 #define DEV_LABEL "atmtcp"
31 #define MAX_VPI_BITS 8
32 #define MAX_VCI_BITS 16
62 atm_force_charge(out_vcc,skb->
truesize);
67 memset(&new_msg->
vcc,0,
sizeof(atm_kptr_t));
70 out_vcc->
push(out_vcc,skb);
92 vcc->
vpi = msg->
addr.sap_addr.vpi;
93 vcc->
vci = msg->
addr.sap_addr.vci;
95 sk_atm(vcc)->sk_err = -msg->
result;
108 wake_up(sk_sleep(sk_atm(vcc)));
113 static void atmtcp_v_dev_close(
struct atm_dev *
dev)
119 static int atmtcp_v_open(
struct atm_vcc *vcc)
123 short vpi = vcc->
vpi;
126 memset(&msg,0,
sizeof(msg));
129 msg.
addr.sap_addr.vpi = vpi;
131 msg.
addr.sap_addr.vci = vci;
138 if (error)
return error;
139 return -sk_atm(vcc)->sk_err;
143 static void atmtcp_v_close(
struct atm_vcc *vcc)
147 memset(&msg,0,
sizeof(msg));
149 msg.
addr.sap_addr.vpi = vcc->
vpi;
150 msg.
addr.sap_addr.vci = vcc->
vci;
156 static int atmtcp_v_ioctl(
struct atm_dev *
dev,
unsigned int cmd,
void __user *
arg)
178 if ((vcc->
vpi >> ci.vpi_bits) ||
179 (vcc->
vci >> ci.vci_bits)) {
200 if (vcc->
pop) vcc->
pop(vcc,skb);
201 else dev_kfree_skb(skb);
205 if (dev_data) out_vcc = dev_data->
vcc;
206 if (!dev_data || !out_vcc) {
207 if (vcc->
pop) vcc->
pop(vcc,skb);
208 else dev_kfree_skb(skb);
209 if (dev_data)
return 0;
216 if (vcc->
pop) vcc->
pop(vcc,skb);
217 else dev_kfree_skb(skb);
225 skb_copy_from_linear_data(skb,
skb_put(new_skb, skb->
len), skb->
len);
226 if (vcc->
pop) vcc->
pop(vcc,skb);
227 else dev_kfree_skb(skb);
228 out_vcc->
push(out_vcc,new_skb);
235 static int atmtcp_v_proc(
struct atm_dev *dev,loff_t *
pos,
char *
page)
241 return sprintf(page,
"persistent, %sconnected\n",
242 dev_data->
vcc ?
"" :
"dis");
246 static void atmtcp_c_close(
struct atm_vcc *vcc)
252 dev_data =
PRIV(atmtcp_dev);
263 static struct atm_vcc *find_vcc(
struct atm_dev *dev,
short vpi,
int vci)
270 head = &
vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
274 if (vcc->
dev == dev &&
275 vcc->
vci == vci && vcc->
vpi == vpi &&
292 if (!skb->
len)
return 0;
296 result = atmtcp_recv_control(
313 __net_timestamp(new_skb);
314 skb_copy_from_linear_data(skb,
skb_put(new_skb, skb->
len), skb->
len);
315 out_vcc->
push(out_vcc,new_skb);
319 if (vcc->
pop) vcc->
pop(vcc,skb);
320 else dev_kfree_skb(skb);
331 .dev_close = atmtcp_v_dev_close,
332 .open = atmtcp_v_open,
333 .close = atmtcp_v_close,
334 .ioctl = atmtcp_v_ioctl,
335 .send = atmtcp_v_send,
336 .proc_read = atmtcp_v_proc,
347 .close = atmtcp_c_close,
348 .send = atmtcp_c_send
352 static struct atm_dev atmtcp_control_dev = {
353 .ops = &atmtcp_c_dev_ops,
360 static int atmtcp_create(
int itf,
int persist,
struct atm_dev **result)
378 PRIV(dev)->persist = persist;
379 if (result) *result =
dev;
384 static int atmtcp_attach(
struct atm_vcc *vcc,
int itf)
391 if (dev->
ops != &atmtcp_v_dev_ops) {
395 if (
PRIV(dev)->vcc) {
403 error = atmtcp_create(itf,0,&dev);
404 if (error)
return error;
407 vcc->
dev = &atmtcp_control_dev;
418 static int atmtcp_create_persistent(
int itf)
420 return atmtcp_create(itf,1,
NULL);
424 static int atmtcp_remove_persistent(
int itf)
431 if (dev->
ops != &atmtcp_v_dev_ops) {
435 dev_data =
PRIV(dev);
436 if (!dev_data->
persist)
return 0;
438 if (
PRIV(dev)->vcc)
return 0;
445 static int atmtcp_ioctl(
struct socket *
sock,
unsigned int cmd,
unsigned long arg)
448 struct atm_vcc *vcc = ATM_SD(sock);
458 err = atmtcp_attach(vcc, (
int) arg);
465 err = atmtcp_create_persistent((
int) arg);
468 err = atmtcp_remove_persistent((
int) arg);
474 static struct atm_ioctl atmtcp_ioctl_ops = {
476 .ioctl = atmtcp_ioctl,
479 static __init int atmtcp_init(
void)
486 static void __exit atmtcp_exit(
void)