8 #include <linux/atmdev.h>
9 #include <linux/atmbr2684.h>
11 /* Written by Marcell GAL <cell@sch.bme.hu> to make use of the */
12 /* ioctls defined in the br2684... kernel patch */
13 /* Compile with cc -o br2684ctl br2684ctl.c -latm */
15 int lastsock, lastitf;
17 void fatal(char *str, int i)
23 int create_br(char *nstr)
28 lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
31 perror("socket creation");
33 /* create the device with ioctl: */
35 if( num>=0 && num<1234567890){
36 struct atm_newif_br2684 ni;
37 ni.backend_num = ATM_BACKEND_BR2684;
38 ni.media = BR2684_MEDIA_ETHERNET;
40 sprintf(ni.ifname, "nas%d", num);
41 err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni);
42 printf("create:%d\n",err);
44 lastitf=num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */
46 fprintf (stderr, "err: strange itf number %d", num );
52 int assign_vcc(char *astr, int encap, int bufsize)
56 struct sockaddr_atmpvc addr;
58 struct atm_backend_br2684 be;
60 memset(&addr, 0, sizeof(addr));
61 err=text2atm(astr,(struct sockaddr *)(&addr), sizeof(addr), T2A_PVC);
62 printf("text2atm:%d\n",err);
64 addr.sap_family = AF_ATMPVC;
65 addr.sap_addr.itf = itf;
66 addr.sap_addr.vpi = 0;
67 addr.sap_addr.vci = vci;
69 fprintf(stderr,"Communicating over ATM %d.%d.%d\n", addr.sap_addr.itf,
73 if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0)
74 fprintf(stderr,"failed to create socket %d", errno);
77 memset(&qos, 0, sizeof(qos));
79 qos.txtp.traffic_class = ATM_UBR;
80 qos.txtp.max_sdu = 1524;
81 qos.txtp.pcr = ATM_MAX_PCR;
84 err=setsockopt(fd,SOL_SOCKET,SO_SNDBUF, &bufsize ,sizeof(bufsize));
85 fprintf(stderr,"setsockopt SO_SNDBUF: (%d) %s\n",err, strerror(err));
87 if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
88 fprintf(stderr,"setsockopt SO_ATMQOS %d", errno);
90 err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc));
93 fatal("failed to connect on socket: ", err);
95 /* attach the vcc to device: */
97 be.backend_num = ATM_BACKEND_BR2684;
98 be.ifspec.method = BR2684_FIND_BYIFNAME;
99 sprintf(be.ifspec.spec.ifname, "nas%d", lastitf);
100 be.fcs_in = BR2684_FCSIN_NO;
101 be.fcs_out = BR2684_FCSOUT_NO;
103 be.encaps = encap ? BR2684_ENCAPS_VC : BR2684_ENCAPS_LLC;
107 err=ioctl (fd, ATM_SETBACKEND, &be);
108 fprintf(stderr, "assign:%d\n",err);
115 printf("usage: %s [-b] [[-c number] [-a [itf.]vpi.vci]*]*\n", s);
119 int main (int argc, char **argv)
121 int c, background=0, encap=0, sndbuf=8192;
126 while ((c = getopt(argc, argv,"a:bc:e:s:")) !=EOF)
129 assign_vcc(optarg, encap, sndbuf);
138 encap=(atoi(optarg));
140 fprintf(stderr, "invalid encap: %s:\n",optarg);
145 sndbuf=(atoi(optarg));
147 fprintf(stderr, "invalid sndbuf: %s:\n",optarg);
154 if (argc != optind) usage(argv[0]);
156 if(lastsock>=0) close(lastsock);
160 /* this seems to be broken, do not use -b for now */
163 fprintf(stderr,"fork returned negative: %d\n", pid);
166 fprintf(stderr,"Background pid: %d\n",pid);
171 while (1) sleep(30); /* to keep the sockets... */