[asterisk-commits] rmudgett: branch group/issue14068 r197085 - /team/group/issue14068/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 27 10:24:49 CDT 2009


Author: rmudgett
Date: Wed May 27 10:24:45 2009
New Revision: 197085

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=197085
Log:
Changes to libpri API for COLP support.

Made able to process PRI subcommands for more events.
Moved the PRI subcommand processing to a common routine.

Modified:
    team/group/issue14068/channels/chan_dahdi.c

Modified: team/group/issue14068/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/issue14068/channels/chan_dahdi.c?view=diff&rev=197085&r1=197084&r2=197085
==============================================================================
--- team/group/issue14068/channels/chan_dahdi.c (original)
+++ team/group/issue14068/channels/chan_dahdi.c Wed May 27 10:24:45 2009
@@ -3226,7 +3226,7 @@
 	default:
 		ast_reason = AST_REDIRECTING_REASON_UNKNOWN;
 		break;
-	}	/* end switch */
+	}
 
 	return ast_reason;
 }
@@ -3254,7 +3254,7 @@
 	default:
 		pri_reason = PRI_REDIR_UNKNOWN;
 		break;
-	}	/* end switch */
+	}
 
 	return pri_reason;
 }
@@ -3294,9 +3294,9 @@
 		ast_presentation = AST_PRES_NUMBER_NOT_AVAILABLE;
 		break;
 	default:
-		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;	/* ?? */
+		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 		break;
-	}	/* end switch */
+	}
 
 	return ast_presentation;
 }
@@ -3336,9 +3336,9 @@
 		pri_presentation = PRES_NUMBER_NOT_AVAILABLE;
 		break;
 	default:
-		pri_presentation = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;	/* ?? */
+		pri_presentation = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 		break;
-	}	/* end switch */
+	}
 
 	return pri_presentation;
 }
@@ -3363,7 +3363,7 @@
 	default:
 		ast_source = AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN;
 		break;
-	}	/* end switch */
+	}
 
 	return ast_source;
 }
@@ -3388,7 +3388,7 @@
 	default:
 		pri_source = PRI_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN;
 		break;
-	}	/* end switch */
+	}
 
 	return pri_source;
 }
@@ -12831,6 +12831,96 @@
 #endif	/* defined(HAVE_PRI) */
 
 #if defined(HAVE_PRI)
+/*!
+ * \internal
+ * \brief Handle the PRI subcommand events.
+ * \since 1.6.3
+ *
+ * \param pri DAHDI PRI private structure.
+ * \param chanpos Channel position in the span.
+ * \param event_id PRI event id
+ * \param channel PRI encoded span/channel
+ * \param subcmds Subcommands to process if any. (Could be NULL).
+ *
+ * \note Assumes the pri->pvts[chanpos]->lock is already obtained.
+ *
+ * \return Nothing
+ */
+static void dahdi_pri_handle_subcmds(struct dahdi_pri *pri, int chanpos, int event_id, int channel, const struct pri_subcommands *subcmds)
+{
+	int index;
+
+	if (!subcmds) {
+		return;
+	}
+	//ast_mutex_lock(&pri->pvts[chanpos]->lock);
+	for (index = 0; index < subcmds->counter_subcmd; ++index) {
+		const struct pri_subcommand *subcmd = &subcmds->subcmd[index];
+		struct ast_channel *owner;
+
+		switch (subcmd->cmd) {
+		case PRI_SUBCMD_CONNECTED_LINE:
+			owner = pri->pvts[chanpos]->owner;
+			if (owner) {
+				struct ast_party_connected_line connected;
+				const struct pri_subcmd_connected_line *cmdcl;
+
+				/* Update the connected line information on the other channel */
+				ast_party_connected_line_init(&connected);
+				cmdcl = &subcmd->connected_line;
+				connected.id.number = (char *) cmdcl->party.id.number;
+				connected.id.name = (char *) cmdcl->party.id.name;
+				connected.id.number_type = cmdcl->party.id.number_type;
+				connected.id.number_presentation =
+					pri_to_ast_presentation(cmdcl->party.id.number_presentation);
+				connected.source =
+					pri_to_ast_connected_line_update_source(cmdcl->party.source);
+				ast_channel_queue_connected_line_update(owner, &connected);
+
+				ast_copy_string(pri->pvts[chanpos]->lastcid_num, cmdcl->party.id.number,
+					sizeof(pri->pvts[chanpos]->lastcid_num));
+				ast_copy_string(pri->pvts[chanpos]->lastcid_name, cmdcl->party.id.name,
+					sizeof(pri->pvts[chanpos]->lastcid_name));
+
+				pri->pvts[chanpos]->subs[SUB_REAL].needcallerid = 1;
+				//dahdi_enable_ec(pri->pvts[chanpos]);
+			}
+			break;
+		case PRI_SUBCMD_REDIRECTING:
+			owner = pri->pvts[chanpos]->owner;
+			if (owner) {
+				struct ast_party_redirecting redirecting = {{0,},};
+				const struct pri_subcmd_redirecting *cmdr;
+
+				cmdr = &subcmd->redirecting;
+				redirecting.from.number = (char *) cmdr->party.from.number;
+				redirecting.from.name = (char *) cmdr->party.from.name;
+				redirecting.from.number_type = cmdr->party.from.number_type;
+				redirecting.from.number_presentation =
+					pri_to_ast_presentation(cmdr->party.from.number_presentation);
+				redirecting.to.number = (char *) cmdr->party.to.number;
+				redirecting.to.name = (char *) cmdr->party.to.name;
+				redirecting.to.number_type = cmdr->party.to.number_type;
+				redirecting.to.number_presentation =
+					pri_to_ast_presentation(cmdr->party.to.number_presentation);
+				redirecting.count = cmdr->party.count;
+				redirecting.reason = pri_to_ast_reason(cmdr->party.reason);
+				ast_channel_queue_redirecting_update(owner, &redirecting);
+			}
+			break;
+		default:
+			ast_log(LOG_WARNING,
+				"Unknown subcommand %d in %s event on channel %d/%d on span %d.\n",
+				subcmd->cmd, pri_event2str(event_id), PRI_SPAN(channel),
+				PRI_CHANNEL(channel), pri->span);
+			break;
+		}
+	}
+	//ast_mutex_unlock(&pri->pvts[chanpos]->lock);
+}
+#endif	/* defined(HAVE_PRI) */
+
+#if defined(HAVE_PRI)
 static void *pri_dchannel(void *vpri)
 {
 	struct dahdi_pri *pri = vpri;
@@ -13186,6 +13276,8 @@
 					chanpos = pri_fixup_principle(pri, chanpos, e->digit.call);
 					if (chanpos > -1) {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->digit.channel,
+							e->digit.subcmds);
 						/* queue DTMF frame if the PBX for this call was already started (we're forwarding KEYPAD_DIGITs further on */
 						if ((pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)
 							&& pri->pvts[chanpos]->call == e->digit.call
@@ -13214,6 +13306,8 @@
 					chanpos = pri_fixup_principle(pri, chanpos, e->ring.call);
 					if (chanpos > -1) {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ring.channel,
+							e->ring.subcmds);
 						/* queue DTMF frame if the PBX for this call was already started (we're forwarding INFORMATION further on */
 						if ((pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)
 							&& pri->pvts[chanpos]->call == e->ring.call
@@ -13344,7 +13438,10 @@
 					chanpos = pri_find_empty_chan(pri, 1);
 				if (chanpos > -1) {
 					struct ast_party_redirecting redirecting = {{0,},};
+
 					ast_mutex_lock(&pri->pvts[chanpos]->lock);
+					dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ring.channel,
+						e->ring.subcmds);
 					if (pri->switchtype == PRI_SWITCH_GR303_TMC) {
 						/* Should be safe to lock CRV AFAIK while bearer is still locked */
 						crv = pri_find_crv(pri, pri_get_crv(pri->pri, e->ring.call, NULL));
@@ -13599,6 +13696,8 @@
 							PRI_SPAN(e->ringing.channel), PRI_CHANNEL(e->ringing.channel), pri->span);
 					} else {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ringing.channel,
+							e->ringing.subcmds);
 						if (ast_strlen_zero(pri->pvts[chanpos]->dop.dialstr)) {
 							dahdi_enable_ec(pri->pvts[chanpos]);
 							pri->pvts[chanpos]->subs[SUB_REAL].needringing = 1;
@@ -13651,6 +13750,9 @@
 				/* Get chan value if e->e is not PRI_EVNT_RINGING */
 				chanpos = pri_find_principle(pri, e->proceeding.channel);
 				if (chanpos > -1) {
+					ast_mutex_lock(&pri->pvts[chanpos]->lock);
+					dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->proceeding.channel,
+						e->proceeding.subcmds);
 					if ((!pri->pvts[chanpos]->progress)
 #ifdef PRI_PROGRESS_MASK
 						|| (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE)
@@ -13674,7 +13776,6 @@
 							}
 						}
 
-						ast_mutex_lock(&pri->pvts[chanpos]->lock);
 						ast_debug(1, "Queuing frame from PRI_EVENT_PROGRESS on channel %d/%d span %d\n",
 							pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
 						dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
@@ -13696,17 +13797,19 @@
 						}
 						pri->pvts[chanpos]->progress = 1;
 						pri->pvts[chanpos]->dialing = 0;
-						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
+					ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 				}
 				break;
 			case PRI_EVENT_PROCEEDING:
 				chanpos = pri_find_principle(pri, e->proceeding.channel);
 				if (chanpos > -1) {
+					ast_mutex_lock(&pri->pvts[chanpos]->lock);
+					dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->proceeding.channel,
+						e->proceeding.subcmds);
 					if (!pri->pvts[chanpos]->proceeding) {
 						struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
 
-						ast_mutex_lock(&pri->pvts[chanpos]->lock);
 						ast_debug(1, "Queuing frame from PRI_EVENT_PROCEEDING on channel %d/%d span %d\n",
 							pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
 						dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
@@ -13728,8 +13831,8 @@
 						}
 						pri->pvts[chanpos]->proceeding = 1;
 						pri->pvts[chanpos]->dialing = 0;
-						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
+					ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 				}
 				break;
 #ifndef PRI_EVENT_FACILITY
@@ -13746,64 +13849,9 @@
 						ast_log(LOG_WARNING, "Facility requested on channel %d/%d not in use on span %d\n",
 							PRI_SPAN(e->facility.channel), PRI_CHANNEL(e->facility.channel), pri->span);
 					} else {
-						int i;
-
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
-						for (i = 0; i < e->facility.subcmds.counter_subcmd; i++) {
-							struct pri_subcommand *subcmd = &e->facility.subcmds.subcmd[i];
-							struct ast_channel *owner;
-
-							switch (subcmd->cmd) {
-							case PRI_SUBCMD_CONNECTED_LINE:
-								owner = pri->pvts[chanpos]->owner;
-								if (owner) {
-									struct ast_party_connected_line connected;
-									struct pri_subcmd_connected_line *cmdcl;
-
-									/* Update the connected line information on the other channel */
-									ast_party_connected_line_init(&connected);
-									cmdcl = &subcmd->connected_line;
-									connected.id.number = cmdcl->party.id.number;
-									connected.id.name = cmdcl->party.id.name;
-									connected.id.number_type = cmdcl->party.id.number_type;
-									connected.id.number_presentation = pri_to_ast_presentation(cmdcl->party.id.number_presentation);
-									connected.source = pri_to_ast_connected_line_update_source(cmdcl->party.source);
-									ast_channel_queue_connected_line_update(owner, &connected);
-
-									ast_copy_string(pri->pvts[chanpos]->lastcid_num, cmdcl->party.id.number, sizeof(pri->pvts[chanpos]->lastcid_num));
-									ast_copy_string(pri->pvts[chanpos]->lastcid_name, cmdcl->party.id.name, sizeof(pri->pvts[chanpos]->lastcid_name));
-
-									pri->pvts[chanpos]->subs[SUB_REAL].needcallerid = 1;
-									//dahdi_enable_ec(pri->pvts[chanpos]);
-								}
-								break;
-							case PRI_SUBCMD_REDIRECTING:
-								owner = pri->pvts[chanpos]->owner;
-								if (owner) {
-									struct ast_party_redirecting redirecting = {{0,},};
-									struct pri_subcmd_redirecting *cmdr;
-
-									cmdr = &subcmd->redirecting;
-									redirecting.from.number = cmdr->party.from.number;
-									redirecting.from.name = cmdr->party.from.name;
-									redirecting.from.number_type = cmdr->party.from.number_type;
-									redirecting.from.number_presentation = pri_to_ast_presentation(cmdr->party.from.number_presentation);
-									redirecting.to.number = cmdr->party.to.number;
-									redirecting.to.name = cmdr->party.to.name;
-									redirecting.to.number_type = cmdr->party.to.number_type;
-									redirecting.to.number_presentation = pri_to_ast_presentation(cmdr->party.to.number_presentation);
-									redirecting.count = 0;
-									redirecting.reason = pri_to_ast_reason(cmdr->party.reason);
-									ast_channel_queue_redirecting_update(owner, &redirecting);
-								}
-								break;
-							default:
-								ast_log(LOG_WARNING,
-									"Illegal subcommand %d in facility request on channel %d/%d not in use on span %d\n",
-									subcmd->cmd, PRI_SPAN(e->facility.channel), PRI_CHANNEL(e->facility.channel), pri->span);
-								break;
-							}
-						}
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->facility.channel,
+							e->facility.subcmds);
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
 				}
@@ -13823,6 +13871,8 @@
 						struct ast_channel *owner;
 
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->answer.channel,
+							e->answer.subcmds);
 						/* Now we can do call progress detection */
 
 						/* We changed this so it turns on the DSP no matter what... progress or no progress.
@@ -13893,6 +13943,8 @@
 					chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
 					if (chanpos > -1) {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->hangup.channel,
+							e->hangup.subcmds);
 						if (!pri->pvts[chanpos]->alreadyhungup) {
 							/* we're calling here dahdi_hangup so once we get there we need to clear p->call after calling pri_hangup */
 							pri->pvts[chanpos]->alreadyhungup = 1;
@@ -13966,6 +14018,8 @@
 					chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
 					if (chanpos > -1) {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->hangup.channel,
+							e->hangup.subcmds);
 						if (pri->pvts[chanpos]->realcall)
 							pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
 						else if (pri->pvts[chanpos]->owner) {
@@ -14112,6 +14166,8 @@
 					chanpos = pri_fixup_principle(pri, chanpos, e->setup_ack.call);
 					if (chanpos > -1) {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+						dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->setup_ack.channel,
+							e->setup_ack.subcmds);
 						pri->pvts[chanpos]->setup_ack = 1;
 						/* Send any queued digits */
 						for (x = 0;x < strlen(pri->pvts[chanpos]->dialdest); x++) {
@@ -14131,7 +14187,10 @@
 						PRI_SPAN(e->notify.channel), PRI_CHANNEL(e->notify.channel), pri->span);
 				} else if (!pri->discardremoteholdretrieval) {
 					struct ast_frame f = { AST_FRAME_CONTROL, };
+
 					ast_mutex_lock(&pri->pvts[chanpos]->lock);
+					dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->notify.channel,
+						e->notify.subcmds);
 					switch (e->notify.info) {
 					case PRI_NOTIFY_REMOTE_HOLD:
 						f.subclass = AST_CONTROL_HOLD;




More information about the asterisk-commits mailing list