[dahdi-commits] tzafrir: linux/trunk r10683 - in /linux/trunk: drivers/dahdi/ drivers/dahdi/w...
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Wed May 23 07:20:32 CDT 2012
Author: tzafrir
Date: Wed May 23 07:20:23 2012
New Revision: 10683
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=10683
Log:
convert span->spantype to enumerated type
* This is a minimal convertion -- everything compiles and looks OK.
* We print a warning for spans registering without a spantype.
* Low-level drivers may later want (but not required)
to fold their internal representations to this canonical
representation -- it will save code and make it more readable.
Signed-off-by: Shaun Ruffell <sruffell at digium.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Modified:
linux/trunk/drivers/dahdi/dahdi-base.c
linux/trunk/drivers/dahdi/dahdi-sysfs.c
linux/trunk/drivers/dahdi/tor2.c
linux/trunk/drivers/dahdi/wcb4xxp/base.c
linux/trunk/drivers/dahdi/wct1xxp.c
linux/trunk/drivers/dahdi/wct4xxp/base.c
linux/trunk/drivers/dahdi/wctdm24xxp/base.c
linux/trunk/drivers/dahdi/wctdm24xxp/xhfc.c
linux/trunk/drivers/dahdi/wcte11xp.c
linux/trunk/drivers/dahdi/wcte12xp/base.c
linux/trunk/drivers/dahdi/xpp/card_bri.c
linux/trunk/drivers/dahdi/xpp/card_fxo.c
linux/trunk/drivers/dahdi/xpp/card_fxs.c
linux/trunk/drivers/dahdi/xpp/card_pri.c
linux/trunk/include/dahdi/kernel.h
Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Wed May 23 07:20:23 2012
@@ -705,6 +705,49 @@
return -1; /* not found -- error */
}
+
+enum spantypes dahdi_str2spantype(const char *name)
+{
+ if (strcasecmp("FXS", name) == 0)
+ return SPANTYPE_ANALOG_FXS;
+ else if (strcasecmp("FXO", name) == 0)
+ return SPANTYPE_ANALOG_FXO;
+ else if (strcasecmp("ANALOG_MIXED", name) == 0)
+ return SPANTYPE_ANALOG_MIXED;
+ else if (strcasecmp("E1", name) == 0)
+ return SPANTYPE_DIGITAL_E1;
+ else if (strcasecmp("T1", name) == 0)
+ return SPANTYPE_DIGITAL_T1;
+ else if (strcasecmp("J1", name) == 0)
+ return SPANTYPE_DIGITAL_J1;
+ else if (strcasecmp("BRI_NT", name) == 0)
+ return SPANTYPE_DIGITAL_BRI_NT;
+ else if (strcasecmp("BRI_TE", name) == 0)
+ return SPANTYPE_DIGITAL_BRI_TE;
+ else if (strcasecmp("BRI_SOFT", name) == 0)
+ return SPANTYPE_DIGITAL_BRI_SOFT;
+ else
+ return SPANTYPE_INVALID;
+}
+EXPORT_SYMBOL(dahdi_str2spantype);
+
+const char *dahdi_spantype2str(enum spantypes st)
+{
+ switch (st) {
+ case SPANTYPE_ANALOG_FXS: return "FXS";
+ case SPANTYPE_ANALOG_FXO: return "FXO";
+ case SPANTYPE_ANALOG_MIXED: return "ANALOG_MIXED";
+ case SPANTYPE_DIGITAL_E1: return "E1";
+ case SPANTYPE_DIGITAL_T1: return "T1";
+ case SPANTYPE_DIGITAL_J1: return "J1";
+ case SPANTYPE_DIGITAL_BRI_NT: return "BRI_NT";
+ case SPANTYPE_DIGITAL_BRI_TE: return "BRI_TE";
+ case SPANTYPE_DIGITAL_BRI_SOFT: return "BRI_SOFT";
+ default:
+ case SPANTYPE_INVALID: return "INVALID";
+ };
+}
+EXPORT_SYMBOL(dahdi_spantype2str);
#ifdef CONFIG_PROC_FS
static const char *sigstr(int sig)
@@ -4265,7 +4308,7 @@
sizeof(spaninfo.location));
}
if (s->spantype) {
- strlcpy(spaninfo.spantype, s->spantype,
+ strlcpy(spaninfo.spantype, dahdi_spantype2str(s->spantype),
sizeof(spaninfo.spantype));
}
@@ -4356,7 +4399,7 @@
if (s->spantype) {
strlcpy(spaninfo_v1.spantype,
- s->spantype,
+ dahdi_spantype2str(s->spantype),
sizeof(spaninfo_v1.spantype));
}
@@ -6829,6 +6872,11 @@
span->name);
span->deflaw = DAHDI_LAW_MULAW;
}
+ if (span->spantype == SPANTYPE_INVALID) {
+ module_printk(KERN_NOTICE,
+ "Warning: Span %s didn't specify a spantype. "
+ "Please fix driver!\n", span->name);
+ }
for (x = 0; x < span->channels; ++x) {
span->chans[x]->span = span;
Modified: linux/trunk/drivers/dahdi/dahdi-sysfs.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-sysfs.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-sysfs.c Wed May 23 07:20:23 2012
@@ -118,10 +118,17 @@
span_attr(name, "%s\n");
span_attr(desc, "%s\n");
-span_attr(spantype, "%s\n");
span_attr(alarms, "0x%x\n");
span_attr(lbo, "%d\n");
span_attr(syncsrc, "%d\n");
+
+static BUS_ATTR_READER(spantype_show, dev, buf)
+{
+ struct dahdi_span *span;
+
+ span = dev_to_span(dev);
+ return sprintf(buf, "%s\n", dahdi_spantype2str(span->spantype));
+}
static BUS_ATTR_READER(local_spanno_show, dev, buf)
{
@@ -474,7 +481,7 @@
/* TODO: Make sure this doesn't overflow the page. */
list_for_each_entry(span, &ddev->spans, device_node) {
count = sprintf(buf, "%d:%s\n",
- local_spanno(span), span->spantype);
+ local_spanno(span), dahdi_spantype2str(span->spantype));
buf += count;
total += count;
}
@@ -490,11 +497,19 @@
int ret;
struct dahdi_span *span;
unsigned int local_span_number;
- char desired_spantype[80];
-
- ret = sscanf(buf, "%u:%70s", &local_span_number, desired_spantype);
- if (ret != 2)
- return -EINVAL;
+ char spantype_name[80];
+ enum spantypes spantype;
+
+ ret = sscanf(buf, "%u:%70s", &local_span_number, spantype_name);
+ if (ret != 2) {
+ dev_err(&ddev->dev, "Wrong input format: '%s'\n", buf);
+ return -EINVAL;
+ }
+ spantype = dahdi_str2spantype(spantype_name);
+ if (spantype == SPANTYPE_INVALID) {
+ dev_err(&ddev->dev, "Invalid spantype: '%s'\n", buf);
+ return -EINVAL;
+ }
list_for_each_entry(span, &ddev->spans, device_node) {
if (local_spanno(span) == local_span_number)
@@ -520,7 +535,7 @@
return -EINVAL;
}
- ret = span->ops->set_spantype(span, &desired_spantype[0]);
+ ret = span->ops->set_spantype(span, spantype);
return (ret < 0) ? ret : count;
}
Modified: linux/trunk/drivers/dahdi/tor2.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/tor2.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/tor2.c (original)
+++ linux/trunk/drivers/dahdi/tor2.c Wed May 23 07:20:23 2012
@@ -290,12 +290,12 @@
s->channels = 24;
s->deflaw = DAHDI_LAW_MULAW;
s->linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
- s->spantype = "T1";
+ s->spantype = SPANTYPE_DIGITAL_T1;
} else {
s->channels = 31;
s->deflaw = DAHDI_LAW_ALAW;
s->linecompat = DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
- s->spantype = "E1";
+ s->spantype = SPANTYPE_DIGITAL_E1;
}
s->chans = tor->chans[x];
s->flags = DAHDI_FLAG_RBS;
Modified: linux/trunk/drivers/dahdi/wcb4xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wcb4xxp/base.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wcb4xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wcb4xxp/base.c Wed May 23 07:20:23 2012
@@ -2505,7 +2505,9 @@
bspan = &b4->spans[i];
bspan->parent = b4;
- bspan->span.spantype = (bspan->te_mode) ? "TE" : "NT";
+ bspan->span.spantype = (bspan->te_mode)
+ ? SPANTYPE_DIGITAL_BRI_TE
+ : SPANTYPE_DIGITAL_BRI_NT;
bspan->span.offset = i;
bspan->span.channels = WCB4XXP_CHANNELS_PER_SPAN;
bspan->span.flags = 0;
Modified: linux/trunk/drivers/dahdi/wct1xxp.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wct1xxp.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wct1xxp.c (original)
+++ linux/trunk/drivers/dahdi/wct1xxp.c Wed May 23 07:20:23 2012
@@ -792,12 +792,12 @@
wc->span.channels = 31;
wc->span.deflaw = DAHDI_LAW_ALAW;
wc->span.linecompat = DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
- wc->span.spantype = "E1";
+ wc->span.spantype = SPANTYPE_DIGITAL_E1;
} else {
wc->span.channels = 24;
wc->span.deflaw = DAHDI_LAW_MULAW;
wc->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
- wc->span.spantype = "T1";
+ wc->span.spantype = SPANTYPE_DIGITAL_T1;
}
for (x=0;x<wc->span.channels;x++) {
sprintf(wc->chans[x]->name, "WCT1/%d/%d", wc->num, x + 1);
Modified: linux/trunk/drivers/dahdi/wct4xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wct4xxp/base.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wct4xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wct4xxp/base.c Wed May 23 07:20:23 2012
@@ -2130,13 +2130,13 @@
switch (ts->linemode) {
case T1:
- ts->span.spantype = "T1";
+ ts->span.spantype = SPANTYPE_DIGITAL_T1;
break;
case E1:
- ts->span.spantype = "E1";
+ ts->span.spantype = SPANTYPE_DIGITAL_E1;
break;
case J1:
- ts->span.spantype = "J1";
+ ts->span.spantype = SPANTYPE_DIGITAL_J1;
break;
}
@@ -2185,40 +2185,47 @@
/**
* t4_set_linemode - Allows user space to change the linemode before spans are assigned.
* @span: span on which to change the linemode.
- * @linemode: Textual description of the new linemode.
+ * @linemode: A value from enumerated spantypes
*
* This callback is used to override the E1/T1 mode jumper settings and set
* the linemode on for each span. Called when the "spantype" attribute
* is written in sysfs under the dahdi_device.
*
*/
-static int t4_set_linemode(struct dahdi_span *span, const char *linemode)
+static int t4_set_linemode(struct dahdi_span *span, enum spantypes linemode)
{
struct t4_span *ts = container_of(span, struct t4_span, span);
struct t4 *wc = ts->owner;
int res = 0;
enum linemode mode;
-
- dev_dbg(&wc->dev->dev, "Setting '%s' to '%s'\n", span->name, linemode);
-
- if (!strcasecmp(span->spantype, linemode))
+ const char *old_name;
+
+ dev_dbg(&wc->dev->dev, "Setting '%s' to '%s'\n", span->name,
+ dahdi_spantype2str(linemode));
+
+ if (span->spantype == linemode)
return 0;
- if (!strcasecmp(linemode, "t1")) {
+ old_name = dahdi_spantype2str(span->spantype);
+ switch (linemode) {
+ case SPANTYPE_DIGITAL_T1:
dev_info(&wc->dev->dev,
- "Changing from %s to T1 line mode.\n", span->spantype);
+ "Changing from %s to T1 line mode.\n", old_name);
mode = T1;
- } else if (!strcasecmp(linemode, "e1")) {
+ break;
+ case SPANTYPE_DIGITAL_E1:
dev_info(&wc->dev->dev,
- "Changing from %s to E1 line mode.\n", span->spantype);
+ "Changing from %s to E1 line mode.\n", old_name);
mode = E1;
- } else if (!strcasecmp(linemode, "j1")) {
+ break;
+ case SPANTYPE_DIGITAL_J1:
dev_info(&wc->dev->dev,
- "Changing from %s to J1 line mode.\n", span->spantype);
+ "Changing from %s to J1 line mode.\n", old_name);
mode = J1;
- } else {
+ break;
+ default:
dev_err(&wc->dev->dev,
- "'%s' is an unknown linemode.\n", linemode);
+ "Got invalid linemode %d from dahdi\n", linemode);
res = -EINVAL;
}
@@ -2295,13 +2302,13 @@
"T%dXXP (PCI) Card %d Span %d", wc->numspans, wc->num, x+1);
switch (ts->linemode) {
case T1:
- ts->span.spantype = "T1";
+ ts->span.spantype = SPANTYPE_DIGITAL_T1;
break;
case E1:
- ts->span.spantype = "E1";
+ ts->span.spantype = SPANTYPE_DIGITAL_E1;
break;
case J1:
- ts->span.spantype = "J1";
+ ts->span.spantype = SPANTYPE_DIGITAL_J1;
break;
}
Modified: linux/trunk/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/base.c Wed May 23 07:20:23 2012
@@ -4520,7 +4520,7 @@
s->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4;
s->span.linecompat |= DAHDI_CONFIG_ESF | DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
s->span.linecompat |= DAHDI_CONFIG_NTTE | DAHDI_CONFIG_TERM;
- s->span.spantype = "TE";
+ s->span.spantype = SPANTYPE_DIGITAL_BRI_TE;
} else {
s->span.ops = &wctdm24xxp_analog_span_ops;
s->span.flags = DAHDI_FLAG_RBS;
Modified: linux/trunk/drivers/dahdi/wctdm24xxp/xhfc.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/xhfc.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/xhfc.c (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/xhfc.c Wed May 23 07:20:23 2012
@@ -2150,7 +2150,9 @@
int all_modes = 0, all_terms = 0;
int i;
- bspan->wspan->span.spantype = (te_mode > 0) ? "TE" : "NT";
+ bspan->wspan->span.spantype = (te_mode > 0)
+ ? SPANTYPE_DIGITAL_BRI_TE
+ : SPANTYPE_DIGITAL_BRI_NT;
bspan->te_mode = te_mode;
bspan->term_on = term_on;
Modified: linux/trunk/drivers/dahdi/wcte11xp.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wcte11xp.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wcte11xp.c (original)
+++ linux/trunk/drivers/dahdi/wcte11xp.c Wed May 23 07:20:23 2012
@@ -1000,12 +1000,12 @@
else
wc->span.channels = 31;
wc->span.deflaw = DAHDI_LAW_ALAW;
- wc->span.spantype = "E1";
+ wc->span.spantype = SPANTYPE_DIGITAL_E1;
wc->span.linecompat = DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
} else {
wc->span.channels = 24;
wc->span.deflaw = DAHDI_LAW_MULAW;
- wc->span.spantype = "T1";
+ wc->span.spantype = SPANTYPE_DIGITAL_T1;
wc->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
}
wc->span.chans = wc->chans;
Modified: linux/trunk/drivers/dahdi/wcte12xp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wcte12xp/base.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/wcte12xp/base.c (original)
+++ linux/trunk/drivers/dahdi/wcte12xp/base.c Wed May 23 07:20:23 2012
@@ -1848,13 +1848,13 @@
if (type == E1) {
wc->span.channels = 31;
- wc->span.spantype = "E1";
+ wc->span.spantype = SPANTYPE_DIGITAL_E1;
wc->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_HDB3 |
DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
wc->span.deflaw = DAHDI_LAW_ALAW;
} else {
wc->span.channels = 24;
- wc->span.spantype = "T1";
+ wc->span.spantype = SPANTYPE_DIGITAL_T1;
wc->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS |
DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
wc->span.deflaw = DAHDI_LAW_MULAW;
@@ -1900,13 +1900,13 @@
* DAHDI).
*
*/
-static int t1xxp_set_linemode(struct dahdi_span *span, const char *linemode)
+static int t1xxp_set_linemode(struct dahdi_span *span, enum spantypes linemode)
{
int res;
struct t1 *wc = container_of(span, struct t1, span);
/* We may already be set to the requested type. */
- if (!strcasecmp(span->spantype, linemode))
+ if (span->spantype == linemode)
return 0;
res = t1_wait_for_ready(wc);
@@ -1920,17 +1920,20 @@
del_timer_sync(&wc->timer);
flush_workqueue(wc->wq);
- if (!strcasecmp(linemode, "t1")) {
+ switch (linemode) {
+ case SPANTYPE_DIGITAL_T1:
dev_info(&wc->vb.pdev->dev,
"Changing from E1 to T1 line mode.\n");
res = t1_software_init(wc, T1);
- } else if (!strcasecmp(linemode, "e1")) {
+ break;
+ case SPANTYPE_DIGITAL_E1:
dev_info(&wc->vb.pdev->dev,
"Changing from T1 to E1 line mode.\n");
res = t1_software_init(wc, E1);
- } else {
+ break;
+ default:
dev_err(&wc->vb.pdev->dev,
- "'%s' is an unknown linemode.\n", linemode);
+ "Got invalid linemode %d from dahdi\n", linemode);
res = -EINVAL;
}
Modified: linux/trunk/drivers/dahdi/xpp/card_bri.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_bri.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_bri.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_bri.c Wed May 23 07:20:23 2012
@@ -793,7 +793,10 @@
/* Nothing to do yet */
return 0;
}
- PHONEDEV(xpd).span.spantype = "BRI";
+ PHONEDEV(xpd).span.spantype =
+ (PHONEDEV(xpd).direction == TO_PHONE)
+ ? SPANTYPE_DIGITAL_BRI_NT
+ : SPANTYPE_DIGITAL_BRI_TE;
PHONEDEV(xpd).span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_CCS;
PHONEDEV(xpd).span.deflaw = DAHDI_LAW_ALAW;
BIT_SET(PHONEDEV(xpd).digital_signalling, 2); /* D-Channel */
Modified: linux/trunk/drivers/dahdi/xpp/card_fxo.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_fxo.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_fxo.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_fxo.c Wed May 23 07:20:23 2012
@@ -554,7 +554,7 @@
BUG_ON(!priv);
timer_count = xpd->timer_count;
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF");
- PHONEDEV(xpd).span.spantype = "FXO";
+ PHONEDEV(xpd).span.spantype = SPANTYPE_ANALOG_FXO;
for_each_line(xpd, i) {
struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
Modified: linux/trunk/drivers/dahdi/xpp/card_fxs.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_fxs.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_fxs.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_fxs.c Wed May 23 07:20:23 2012
@@ -586,7 +586,7 @@
priv = xpd->priv;
BUG_ON(!priv);
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
- PHONEDEV(xpd).span.spantype = "FXS";
+ PHONEDEV(xpd).span.spantype = SPANTYPE_ANALOG_FXS;
for_each_line(xpd, i) {
struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
Modified: linux/trunk/drivers/dahdi/xpp/card_pri.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_pri.c?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_pri.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_pri.c Wed May 23 07:20:23 2012
@@ -101,20 +101,20 @@
[PRI_PROTO_J1] = "J1"
};
+static enum spantypes pri_protocol2spantype(enum pri_protocol pri_protocol)
+{
+ switch (pri_protocol) {
+ case PRI_PROTO_E1: return SPANTYPE_DIGITAL_E1;
+ case PRI_PROTO_T1: return SPANTYPE_DIGITAL_T1;
+ case PRI_PROTO_J1: return SPANTYPE_DIGITAL_J1;
+ default:
+ return SPANTYPE_INVALID;
+ }
+}
+
static const char *pri_protocol_name(enum pri_protocol pri_protocol)
{
return protocol_names[pri_protocol];
-}
-
-static enum pri_protocol pri_protocol_bystr(const char *spantype)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(protocol_names); i++) {
- if (strcasecmp(protocol_names[i], spantype) == 0)
- return i;
- }
- return PRI_PROTO_0;
}
static int pri_num_channels(enum pri_protocol pri_protocol)
@@ -1077,14 +1077,28 @@
return -EINVAL;
}
-static int pri_set_spantype(struct dahdi_span *span, const char *spantype)
+static int pri_set_spantype(struct dahdi_span *span, enum spantypes spantype)
{
struct phonedev *phonedev = container_of(span, struct phonedev, span);
xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
enum pri_protocol set_proto = PRI_PROTO_0;
- XPD_INFO(xpd, "%s: %s\n", __func__, spantype);
- set_proto = pri_protocol_bystr(spantype);
+ XPD_INFO(xpd, "%s: %s\n", __func__, dahdi_spantype2str(spantype));
+ switch (spantype) {
+ case SPANTYPE_DIGITAL_E1:
+ set_proto = PRI_PROTO_E1;
+ break;
+ case SPANTYPE_DIGITAL_T1:
+ set_proto = PRI_PROTO_T1;
+ break;
+ case SPANTYPE_DIGITAL_J1:
+ set_proto = PRI_PROTO_J1;
+ break;
+ default:
+ XPD_NOTICE(xpd, "%s: bad spantype '%s'\n",
+ __func__, dahdi_spantype2str(spantype));
+ return -EINVAL;
+ }
return set_pri_proto(xpd, set_proto);
}
@@ -1361,7 +1375,7 @@
priv = xpd->priv;
BUG_ON(!xbus);
XPD_DBG(GENERAL, xpd, "\n");
- PHONEDEV(xpd).span.spantype = pri_protocol_name(priv->pri_protocol);
+ PHONEDEV(xpd).span.spantype = pri_protocol2spantype(priv->pri_protocol);
PHONEDEV(xpd).span.linecompat = pri_linecompat(priv->pri_protocol);
PHONEDEV(xpd).span.deflaw = priv->deflaw;
PHONEDEV(xpd).span.alarms = DAHDI_ALARM_NONE;
Modified: linux/trunk/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/include/dahdi/kernel.h?view=diff&rev=10683&r1=10682&r2=10683
==============================================================================
--- linux/trunk/include/dahdi/kernel.h (original)
+++ linux/trunk/include/dahdi/kernel.h Wed May 23 07:20:23 2012
@@ -792,6 +792,21 @@
#define DAHDI_FLAG_TXUNDERRUN DAHDI_FLAG(TXUNDERRUN)
#define DAHDI_FLAG_RXOVERRUN DAHDI_FLAG(RXOVERRUN)
+enum spantypes {
+ SPANTYPE_INVALID = 0,
+ SPANTYPE_ANALOG_FXS,
+ SPANTYPE_ANALOG_FXO,
+ SPANTYPE_ANALOG_MIXED,
+ SPANTYPE_DIGITAL_E1,
+ SPANTYPE_DIGITAL_T1,
+ SPANTYPE_DIGITAL_J1,
+ SPANTYPE_DIGITAL_BRI_NT,
+ SPANTYPE_DIGITAL_BRI_TE,
+ SPANTYPE_DIGITAL_BRI_SOFT,
+};
+const char *dahdi_spantype2str(enum spantypes st);
+enum spantypes dahdi_str2spantype(const char *name);
+
struct file;
struct dahdi_span_ops {
@@ -890,7 +905,7 @@
/*! Called when the spantype / linemode is changed before the span is
* assigned a number. */
- int (*set_spantype)(struct dahdi_span *span, const char *spantype);
+ int (*set_spantype)(struct dahdi_span *span, enum spantypes st);
};
/**
@@ -921,7 +936,7 @@
spinlock_t lock;
char name[40]; /*!< Span name */
char desc[80]; /*!< Span description */
- const char *spantype; /*!< span type in text form */
+ enum spantypes spantype; /*!< span type */
int deflaw; /*!< Default law (DAHDI_MULAW or DAHDI_ALAW) */
int alarms; /*!< Pending alarms on span */
unsigned long flags;
More information about the dahdi-commits
mailing list