diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 7cf585a3106d9f10a8ee580c2564e9de3efa8655..09f4612590b950e80e4ec1850d738ec646472570 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -12270,6 +12270,7 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf,
 						pris[span].pri.nsf = conf->pri.pri.nsf;
 						pris[span].pri.dialplan = conf->pri.pri.dialplan;
 						pris[span].pri.localdialplan = conf->pri.pri.localdialplan;
+						pris[span].pri.cpndialplan = conf->pri.pri.cpndialplan;
 						pris[span].pri.pvts[pris[span].pri.numchans++] = tmp->sig_pvt;
 						pris[span].pri.minunused = conf->pri.pri.minunused;
 						pris[span].pri.minidle = conf->pri.pri.minidle;
@@ -16971,6 +16972,8 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct
 					confp->pri.pri.localdialplan = PRI_INTERNATIONAL_ISDN + 1;
 				} else if (!strcasecmp(v->value, "local")) {
 					confp->pri.pri.localdialplan = PRI_LOCAL_ISDN + 1;
+				} else if (!strcasecmp(v->value, "from_channel")) {
+					confp->pri.pri.localdialplan = 0;
 				} else if (!strcasecmp(v->value, "dynamic")) {
 					confp->pri.pri.localdialplan = -1;
 				} else if (!strcasecmp(v->value, "redundant")) {
@@ -16978,6 +16981,26 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct
 				} else {
 					ast_log(LOG_WARNING, "Unknown PRI localdialplan '%s' at line %d.\n", v->value, v->lineno);
 				}
+			} else if (!strcasecmp(v->name, "pricpndialplan")) {
+				if (!strcasecmp(v->value, "national")) {
+					confp->pri.pri.cpndialplan = PRI_NATIONAL_ISDN + 1;
+				} else if (!strcasecmp(v->value, "unknown")) {
+					confp->pri.pri.cpndialplan = PRI_UNKNOWN + 1;
+				} else if (!strcasecmp(v->value, "private")) {
+					confp->pri.pri.cpndialplan = PRI_PRIVATE + 1;
+				} else if (!strcasecmp(v->value, "international")) {
+					confp->pri.pri.cpndialplan = PRI_INTERNATIONAL_ISDN + 1;
+				} else if (!strcasecmp(v->value, "local")) {
+					confp->pri.pri.cpndialplan = PRI_LOCAL_ISDN + 1;
+				} else if (!strcasecmp(v->value, "from_channel")) {
+					confp->pri.pri.cpndialplan = 0;
+				} else if (!strcasecmp(v->value, "dynamic")) {
+					confp->pri.pri.cpndialplan = -1;
+				} else if (!strcasecmp(v->value, "redundant")) {
+					confp->pri.pri.cpndialplan = -2;
+				} else {
+					ast_log(LOG_WARNING, "Unknown PRI cpndialplan '%s' at line %d.\n", v->value, v->lineno);
+				}
 			} else if (!strcasecmp(v->name, "switchtype")) {
 				if (!strcasecmp(v->value, "national"))
 					confp->pri.pri.switchtype = PRI_SWITCH_NI2;
diff --git a/channels/sig_pri.c b/channels/sig_pri.c
index 27e5dcf0b6730cf3e5fd51f36b8bdb875f9c9cf1..2efc666abee8be4beb91ef28f29a0b46cc634d9a 100644
--- a/channels/sig_pri.c
+++ b/channels/sig_pri.c
@@ -7253,6 +7253,9 @@ int sig_pri_call(struct sig_pri_chan *p, struct ast_channel *ast, char *rdest, i
 		} else {
 			prilocaldialplan = PRI_LOCAL_ISDN;
 		}
+	} else if (prilocaldialplan == -1) {
+		/* Use the numbering plan passed in. */
+		prilocaldialplan = ast->connected.id.number.plan;
 	}
 	if (l != NULL) {
 		while (*l > '9' && *l != '*' && *l != '#') {
@@ -7558,10 +7561,46 @@ int sig_pri_indicate(struct sig_pri_chan *p, struct ast_channel *chan, int condi
 		ast_debug(1, "Received AST_CONTROL_CONNECTED_LINE on %s\n", chan->name);
 		if (p->pri && !pri_grab(p, p->pri)) {
 			struct pri_party_connected_line connected;
+			int dialplan;
+			int prefix_strip;
 
 			memset(&connected, 0, sizeof(connected));
 			sig_pri_party_id_from_ast(&connected.id, &chan->connected.id);
 
+			/* Determine the connected line numbering plan to actually use. */
+			switch (p->pri->cpndialplan) {
+			case -2:/* redundant */
+			case -1:/* dynamic */
+				/* compute dynamically */
+				prefix_strip = 0;
+				if (!strncmp(connected.id.number.str, p->pri->internationalprefix,
+					strlen(p->pri->internationalprefix))) {
+					prefix_strip = strlen(p->pri->internationalprefix);
+					dialplan = PRI_INTERNATIONAL_ISDN;
+				} else if (!strncmp(connected.id.number.str, p->pri->nationalprefix,
+					strlen(p->pri->nationalprefix))) {
+					prefix_strip = strlen(p->pri->nationalprefix);
+					dialplan = PRI_NATIONAL_ISDN;
+				} else {
+					dialplan = PRI_LOCAL_ISDN;
+				}
+				connected.id.number.plan = dialplan;
+
+				if (prefix_strip && p->pri->cpndialplan != -2) {
+					/* Strip the prefix from the connected line number. */
+					memmove(connected.id.number.str,
+						connected.id.number.str + prefix_strip,
+						strlen(connected.id.number.str + prefix_strip) + 1);
+				}
+				break;
+			case 0:/* from_channel */
+				/* Use the numbering plan passed in. */
+				break;
+			default:
+				connected.id.number.plan = p->pri->cpndialplan - 1;
+				break;
+			}
+
 			pri_connected_line_update(p->pri->pri, p->call, &connected);
 			pri_rel(p->pri);
 		}
diff --git a/channels/sig_pri.h b/channels/sig_pri.h
index 1c375080026d5f63394245ccc39d806ce179a8dc..53a4b860422e1a1a5605f30ade563ea2e1ca5e08 100644
--- a/channels/sig_pri.h
+++ b/channels/sig_pri.h
@@ -404,6 +404,7 @@ struct sig_pri_span {
 	unsigned int append_msn_to_user_tag:1;
 	int dialplan;							/*!< Dialing plan */
 	int localdialplan;						/*!< Local dialing plan */
+	int cpndialplan;						/*!< Connected party dialing plan */
 	char internationalprefix[10];			/*!< country access code ('00' for european dialplans) */
 	char nationalprefix[10];				/*!< area access code ('0' for european dialplans) */
 	char localprefix[20];					/*!< area access code + area code ('0'+area code for european dialplans) */
diff --git a/configs/chan_dahdi.conf.sample b/configs/chan_dahdi.conf.sample
index 0c0bed72265ceaa176d41085911fac8d94509ec8..c176789a6904845686f18142364ed4612c08062a 100644
--- a/configs/chan_dahdi.conf.sample
+++ b/configs/chan_dahdi.conf.sample
@@ -92,33 +92,59 @@
 ;          Send out the specified digits as keypad digits.
 ;
 ; PRI Dialplan: The ISDN-level Type Of Number (TON) or numbering plan, used for
-; the dialed number.  For most installations, leaving this as 'unknown' (the
-; default) works in the most cases.  In some very unusual circumstances, you
-; may need to set this to 'dynamic' or 'redundant'.  Note that if you set one
-; of the others, you will be unable to dial another class of numbers.  For
-; example, if you set 'national', you will be unable to dial local or
-; international numbers.
+; the dialed number.  Leaving this as 'unknown' (the default) works for most
+; cases.  In some very unusual circumstances, you may need to set this to
+; 'dynamic' or 'redundant'.
+;
+; unknown:        Unknown
+; private:        Private ISDN
+; local:          Local ISDN
+; national:       National ISDN
+; international:  International ISDN
+; dynamic:        Dynamically selects the appropriate dialplan using the
+;                 prefix settings.
+; redundant:      Same as dynamic, except that the underlying number is not
+;                 changed (not common)
+;
+; pridialplan cannot be changed on reload.
+;pridialplan=unknown
 ;
 ; PRI Local Dialplan:  Only RARELY used for PRI (sets the calling number's
 ; numbering plan).  In North America, the typical use is sending the 10 digit
 ; callerID number and setting the prilocaldialplan to 'national' (the default).
 ; Only VERY rarely will you need to change this.
 ;
-; Neither pridialplan nor prilocaldialplan can be changed on reload.
-;
 ; unknown:        Unknown
 ; private:        Private ISDN
 ; local:          Local ISDN
 ; national:       National ISDN
 ; international:  International ISDN
-; dynamic:        Dynamically selects the appropriate dialplan
+; from_channel:   Use the CALLERID(ton) value from the channel.
+; dynamic:        Dynamically selects the appropriate dialplan using the
+;                 prefix settings.
 ; redundant:      Same as dynamic, except that the underlying number is not
 ;                 changed (not common)
 ;
-;pridialplan=unknown
+; prilocaldialplan cannot be changed on reload.
 ;prilocaldialplan=national
 ;
-; pridialplan may be also set at dialtime, by prefixing the dialled number with
+; PRI Connected Line Dialplan:  Sets the connected party number's numbering plan.
+;
+; unknown:        Unknown
+; private:        Private ISDN
+; local:          Local ISDN
+; national:       National ISDN
+; international:  International ISDN
+; from_channel:   Use the CONNECTEDLINE(ton) value from the channel.
+; dynamic:        Dynamically selects the appropriate dialplan using the
+;                 prefix settings.
+; redundant:      Same as dynamic, except that the underlying number is not
+;                 changed (not common)
+;
+; pricpndialplan cannot be changed on reload.
+;pricpndialplan=from_channel
+;
+; pridialplan may be also set at dialtime, by prefixing the dialed number with
 ; one of the following letters:
 ; U - Unknown
 ; I - International
@@ -129,7 +155,7 @@
 ; R - Reserved (should probably never be used but is included for completeness)
 ;
 ; Additionally, you may also set the following NPI bits (also by prefixing the
-; dialled string with one of the following letters):
+; dialed string with one of the following letters):
 ; u - Unknown
 ; e - E.163/E.164 (ISDN/telephony)
 ; x - X.121 (Data)
@@ -139,10 +165,11 @@
 ; r - Reserved (should probably never be used but is included for completeness)
 ;
 ; You may also set the prilocaldialplan in the same way, but by prefixing the
-; Caller*ID Number, rather than the dialled number.  Please note that telcos
-; which require this kind of additional manipulation of the TON/NPI are *rare*.
-; Most telco PRIs will work fine simply by setting pridialplan to unknown or
-; dynamic.
+; Caller*ID Number rather than the dialed number.
+
+; Please note that telcos which require this kind of additional manipulation
+; of the TON/NPI are *rare*.  Most telco PRIs will work fine simply by
+; setting pridialplan to unknown or dynamic.
 ;
 ;
 ; PRI caller ID prefixes based on the given TON/NPI (dialplan)