--- channels/chan_zap.dist.c	2006-08-23 20:14:22.160416000 +0200
+++ channels/chan_zap.c	2006-08-28 21:17:07.175523000 +0200
@@ -2085,6 +2085,66 @@
 				pridialplan = PRI_LOCAL_ISDN;
  			}
  		}
+		switch (*(c + p->stripmsd)) {
+			case 'U':
+				pridialplan = (PRI_TON_UNKNOWN << 4);
+				++c;
+				break;
+			case 'I':
+				pridialplan = (PRI_TON_INTERNATIONAL << 4);
+				++c;
+				break;
+			case 'N':
+				pridialplan = (PRI_TON_NATIONAL << 4);
+				++c;
+				break;
+			case 'L':
+				pridialplan = (PRI_TON_NET_SPECIFIC << 4);
+				++c;
+				break;
+			case 'S':
+				pridialplan = (PRI_TON_SUBSCRIBER << 4);
+				++c;
+				break;
+			case 'A':
+				pridialplan = (PRI_TON_ABBREVIATED << 4);
+				++c;
+				break;
+			case 'R':
+				pridialplan = (PRI_TON_RESERVED << 4);
+				++c;
+				break;
+		}
+		switch (*c) {
+			case 'u':
+				pridialplan |= PRI_NPI_UNKNOWN;
+				++c;
+				break;
+			case 'e':
+				pridialplan |= PRI_NPI_E163_E164;
+				++c;
+				break;
+			case 'x':
+				pridialplan |= PRI_NPI_X121;
+				++c;
+				break;
+			case 'f':
+				pridialplan |= PRI_NPI_F69;
+				++c;
+				break;
+			case 'n':
+				pridialplan |= PRI_NPI_NATIONAL;
+				++c;
+				break;
+			case 'p':
+				pridialplan |= PRI_NPI_PRIVATE;
+				++c;
+				break;
+			case 'r':
+				pridialplan |= PRI_NPI_RESERVED;
+				++c;
+				break;
+		}
  		pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan, s ? 1 : 0);
 
 		ldp_strip = 0;
@@ -2100,6 +2160,70 @@
 				prilocaldialplan = PRI_LOCAL_ISDN;
 			}
 		}
+	        if (l != NULL) {
+	                switch (*l) {
+	                        case 'U':
+	                                prilocaldialplan = (PRI_TON_UNKNOWN << 4);
+	                                ++l;
+	                                break;
+	                        case 'I':
+	                                prilocaldialplan = (PRI_TON_INTERNATIONAL << 4);
+	                                ++l;
+	                                break;
+	                        case 'N':
+	                                prilocaldialplan = (PRI_TON_NATIONAL << 4);
+	                                ++l;
+	                                break;
+	                        case 'L':
+	                                prilocaldialplan = (PRI_TON_NET_SPECIFIC << 4);
+	                                ++l;
+	                                break;
+	                        case 'S':
+	                                prilocaldialplan = (PRI_TON_SUBSCRIBER << 4);
+	                                ++l;
+	                                break;
+				case 'A':
+					prilocaldialplan = (PRI_TON_ABBREVIATED << 4);
+					++l;
+					break;
+	                        case 'R':
+	                                prilocaldialplan = (PRI_TON_RESERVED << 4);
+	                                ++l;
+	                                break;
+	                }
+	        }
+	        if (l != NULL) {
+	                switch (*l) {
+	                        case 'u':
+	                                prilocaldialplan |= PRI_NPI_UNKNOWN;
+	                                ++l;
+	                                break;
+	                        case 'e':
+	                                prilocaldialplan |= PRI_NPI_E163_E164;
+	                                ++l;
+	                                break;
+	                        case 'x':
+	                                prilocaldialplan |= PRI_NPI_X121;
+	                                ++l;
+	                                break;
+	                        case 'f':
+	                                prilocaldialplan |= PRI_NPI_F69;
+	                                ++l;
+	                                break;
+	                        case 'n':
+	                                prilocaldialplan |= PRI_NPI_NATIONAL;
+	                                ++l;
+	                                break;
+	                        case 'p':
+	                                prilocaldialplan |= PRI_NPI_PRIVATE;
+	                                ++l;
+	                                break;
+	                        case 'r':
+	                                prilocaldialplan |= PRI_NPI_RESERVED;
+	                                ++l;
+	                                break;
+	                }
+	        }
 		pri_sr_set_caller(sr, l ? (l + ldp_strip) : NULL, n, prilocaldialplan,
 			p->use_callingpres ? ast->cid.cid_pres : (l ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_NUMBER_NOT_AVAILABLE));
 		pri_sr_set_redirecting(sr, ast->cid.cid_rdnis, p->pri->localdialplan - 1, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
