[dahdi-commits] sruffell: tools/trunk r9352 - /tools/trunk/dahdi_cfg.c

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Mon Sep 20 15:30:53 CDT 2010


Author: sruffell
Date: Mon Sep 20 15:30:49 2010
New Revision: 9352

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9352
Log:
dahdi_cfg: DAHDI_INDIRECT -> DAHDI_SPECIFY when configuring pciradio channels.

While slightly less efficient, this is only used when configuring the
channels initially (not the hot path) and allows dahdi-base.c to assume
that the open "file" pointer always refers to the channel on which to
perform the operation.

Signed-off-by: Shaun Ruffell <sruffell at digium.com>

Modified:
    tools/trunk/dahdi_cfg.c

Modified: tools/trunk/dahdi_cfg.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/dahdi_cfg.c?view=diff&rev=9352&r1=9351&r2=9352
==============================================================================
--- tools/trunk/dahdi_cfg.c (original)
+++ tools/trunk/dahdi_cfg.c Mon Sep 20 15:30:49 2010
@@ -174,16 +174,6 @@
 	default:
 		return "Unknown";
 	}
-}
-
-int ind_ioctl(int channo, int fd, int op, void *data)
-{
-	struct dahdi_indirect_data ind;
-
-	ind.chan = channo;
-	ind.op = op;
-	ind.data = data;
-	return ioctl(fd, DAHDI_INDIRECT, &ind);
 }
 
 static void clear_fields()
@@ -1091,6 +1081,7 @@
 	int res = 0;
 	int x,i,n;
 	struct dahdi_radio_param p;
+	int chanfd;
 
 	toneindex = 1;
 	bzero(chans, sizeof(chans));
@@ -1099,8 +1090,21 @@
 		return -1;
 	for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
 		if (chans[x]) {
+			const char *CHANNEL_FILENAME = "/dev/dahdi/channel";
+			chanfd = open(CHANNEL_FILENAME, O_RDWR);
+			if (-1 == chanfd) {
+				error("Failed to open '%s'.\n", CHANNEL_FILENAME);
+				exit(-1);
+			}
+
+			res = ioctl(chanfd, DAHDI_SPECIFY, &x);
+			if (res) {
+				error("Failed to open channel %d.\n", x);
+				close(chanfd);
+				continue;
+			}
 			p.radpar = DAHDI_RADPAR_NUMTONES;
-			if (ind_ioctl(x,fd,DAHDI_RADIO_GETPARAM,&p) == -1)
+			if (ioctl(chanfd,DAHDI_RADIO_GETPARAM,&p) == -1)
 				n = 0;
 			else
 				n = p.data;
@@ -1108,7 +1112,7 @@
 			if (n)
 			{
 				p.radpar = DAHDI_RADPAR_INITTONE;
-				if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1) {
+				if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1) {
 					error("Cannot init tones for channel %d\n",x);
 				}
 				if (!rxtones[0]) for(i = 1; i <= n; i++)
@@ -1118,7 +1122,7 @@
 						p.radpar = DAHDI_RADPAR_RXTONE;
 						p.index = i;
 						p.data = rxtones[i];
-						if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+						if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 							error("Cannot set rxtone on channel %d\n",x);
 					}
 					if (rxtags[i])
@@ -1126,7 +1130,7 @@
 						p.radpar = DAHDI_RADPAR_RXTONECLASS;
 						p.index = i;
 						p.data = rxtags[i];
-						if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+						if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 							error("Cannot set rxtag on channel %d\n",x);
 					}
 					if (txtones[i])
@@ -1134,7 +1138,7 @@
 						p.radpar = DAHDI_RADPAR_TXTONE;
 						p.index = i;
 						p.data = txtones[i];
-						if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+						if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 							error("Cannot set txtone on channel %d\n",x);
 					}
 				} else { /* if we may have DCS receive */
@@ -1143,7 +1147,7 @@
 						p.radpar = DAHDI_RADPAR_RXTONE;
 						p.index = 0;
 						p.data = rxtones[0];
-						if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+						if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 							error("Cannot set DCS rxtone on channel %d\n",x);
 					}
 				}
@@ -1152,7 +1156,7 @@
 					p.radpar = DAHDI_RADPAR_TXTONE;
 					p.index = 0;
 					p.data = txtones[0];
-					if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+					if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 						error("Cannot set default txtone on channel %d\n",x);
 				}
 			}
@@ -1160,41 +1164,43 @@
 			{
 				p.radpar = DAHDI_RADPAR_DEBOUNCETIME;
 				p.data = debouncetime;
-				if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+				if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 					error("Cannot set debouncetime on channel %d\n",x);
 			}
 			if (bursttime)
 			{
 				p.radpar = DAHDI_RADPAR_BURSTTIME;
 				p.data = bursttime;
-				if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+				if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 					error("Cannot set bursttime on channel %d\n",x);
 			}
 			p.radpar = DAHDI_RADPAR_DEEMP;
 			p.data = deemp;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			p.radpar = DAHDI_RADPAR_PREEMP;
 			p.data = preemp;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			p.radpar = DAHDI_RADPAR_TXGAIN;
 			p.data = txgain;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			p.radpar = DAHDI_RADPAR_RXGAIN;
 			p.data = rxgain;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			p.radpar = DAHDI_RADPAR_INVERTCOR;
 			p.data = invertcor;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			p.radpar = DAHDI_RADPAR_EXTRXTONE;
 			p.data = exttone;
-			ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p);
+			ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p);
 			if (corthresh)
 			{
 				p.radpar = DAHDI_RADPAR_CORTHRESH;
 				p.data = corthresh - 1;
-				if (ind_ioctl(x,fd,DAHDI_RADIO_SETPARAM,&p) == -1)
+				if (ioctl(chanfd,DAHDI_RADIO_SETPARAM,&p) == -1)
 					error("Cannot set corthresh on channel %d\n",x);
 			}
+
+			close(chanfd);
 		}
 	}
 	clear_fields();




More information about the dahdi-commits mailing list