Index: channels/chan_skinny.c
===================================================================
--- channels/chan_skinny.c	(revision 382008)
+++ channels/chan_skinny.c	(working copy)
@@ -2519,12 +2519,11 @@
 	transmit_response(d, req);
 }
 
-static void send_callinfo(struct skinny_subchannel *sub)
+static void send_callinfo(struct skinny_subchannel *sub, struct ast_party_id otherParty)
 {
-	struct ast_channel *ast;
+	struct ast_party_caller *us;
 	struct skinny_device *d;
 	struct skinny_line *l;
-	struct ast_party_id connected_id;
 	char *fromname;
 	char *fromnum;
 	char *toname;
@@ -2534,26 +2533,30 @@
 		return;
 	}
 
-	ast = sub->owner;
 	l = sub->line;
 	d = l->device;
-	connected_id = ast_channel_connected_effective_id(ast);
+	us = ast_channel_caller(sub->owner);
 
 	if (sub->calldirection == SKINNY_INCOMING) {
-		if ((ast_party_id_presentation(&connected_id) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
-			fromname = S_COR(connected_id.name.valid, connected_id.name.str, "");
-			fromnum = S_COR(connected_id.number.valid, connected_id.number.str, "");
+		if ((ast_party_id_presentation(&otherParty) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
+			fromname = S_COR(otherParty.name.valid, otherParty.name.str, "");
+			fromnum = S_COR(otherParty.number.valid, otherParty.number.str, "");
 		} else {
 			fromname = "";
 			fromnum = "";
 		}
-		toname = S_COR(ast_channel_caller(ast)->id.name.valid, ast_channel_caller(ast)->id.name.str, "");
-		tonum = S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, "");
+		toname = S_COR(us->id.name.valid, us->id.name.str, "");
+		tonum = S_COR(us->id.number.valid, us->id.number.str, "");
 	} else if (sub->calldirection == SKINNY_OUTGOING) {
-		fromname = S_COR(ast_channel_caller(ast)->id.name.valid, ast_channel_caller(ast)->id.name.str, "");
-		fromnum = S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, "");
-		toname = S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, "");
-		tonum = S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, l->lastnumberdialed);
+		fromname = S_COR(us->id.name.valid, us->id.name.str, "");
+		fromnum = S_COR(us->id.number.valid, us->id.number.str, "");
+		if ((ast_party_id_presentation(&otherParty) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
+			toname = S_COR(otherParty.name.valid, otherParty.name.str, "");
+			tonum = S_COR(otherParty.number.valid, otherParty.number.str, sub->exten);
+		} else {
+			toname = "";
+			tonum = sub->exten;
+		}
 	} else {
 		ast_verb(1, "Error sending Callinfo to %s(%d) - No call direction in sub\n", d->name, l->instance);
 		return;
@@ -2565,7 +2568,7 @@
 		transmit_callinfo_variable(d, l->instance, sub->callid, fromname, fromnum, toname, tonum, sub->calldirection, sub->origtonum, sub->origtoname);
 	}
 }
-
+	
 static void push_callinfo(struct skinny_subline *subline, struct skinny_subchannel *sub)
 {
 	struct ast_channel *ast;
@@ -3478,6 +3481,27 @@
 	return 0;
 }
 
+static void update_redirectingline(struct skinny_subchannel *sub, const void *data, size_t datalen)
+{
+	struct ast_channel *c = sub->owner;
+	struct skinny_line *l = sub->line;
+	struct skinny_device *d = l->device;
+
+	if (!d->session) {
+		return;
+	}
+
+	if (!ast_channel_caller(c)->id.number.valid
+		|| ast_strlen_zero(ast_channel_caller(c)->id.number.str)
+		|| !ast_channel_connected(c)->id.number.valid
+		|| ast_strlen_zero(ast_channel_connected(c)->id.number.str))
+		return;
+
+	SKINNY_DEBUG(DEBUG_SUB, 3, "Sub %d - Updating redirecting\n", sub->callid);
+
+	send_callinfo(sub, ast_channel_redirecting_effective_to(sub->owner));
+}
+
 static void update_connectedline(struct skinny_subchannel *sub, const void *data, size_t datalen)
 {
 	struct ast_channel *c = sub->owner;
@@ -3504,7 +3528,7 @@
 
 	SKINNY_DEBUG(DEBUG_SUB, 3, "Sub %d - Updating\n", sub->callid);
 
-	send_callinfo(sub);
+	send_callinfo(sub, ast_channel_connected_effective_id(sub->owner));
 }
 
 static void mwi_event_cb(const struct ast_event *event, void *userdata)
@@ -5334,6 +5358,9 @@
 	case AST_CONTROL_CONNECTED_LINE:
 		update_connectedline(sub, data, datalen);
 		break;
+	case AST_CONTROL_REDIRECTING:
+		update_redirectingline(sub, data, datalen);
+		break;
 	default:
 		ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
 		/* fallthrough */
@@ -5561,7 +5588,6 @@
 				subline->sub = sub;
 				sub->subline = subline;
 				subline->callid = sub->callid;
-				send_callinfo(sub);
 				AST_LIST_TRAVERSE(&lines, tmpline, all) {
 					AST_LIST_TRAVERSE(&tmpline->sublines, tmpsubline, list) {
 						if (!(subline == tmpsubline)) {
@@ -5666,7 +5692,6 @@
 		sub->callid, substate2str(sub->substate), substate2str(actualstate));
 
 	if (actualstate == sub->substate) {
-		send_callinfo(sub);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_HOLD);
 		return;
 	}
@@ -5779,7 +5804,7 @@
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_RINGOUT);
 		transmit_dialednumber(d, sub->exten, l->instance, sub->callid);
 		send_displaypromptstatus(d, OCTAL_RINGOUT, "", 0, l->instance, sub->callid);
-		send_callinfo(sub);
+		//send_callinfo(sub);
 		sub->substate = SUBSTATE_RINGOUT;
 		break;
 	case SUBSTATE_RINGIN:
@@ -5793,7 +5818,7 @@
 		transmit_selectsoftkeys(d, l->instance, sub->callid, KEYDEF_RINGIN, KEYMASK_ALL);
 		send_displaypromptstatus(d, OCTAL_FROM, fromnum, 0, l->instance, sub->callid);
 		send_displayprinotify(d, OCTAL_FROM, fromnum, 10, 5);
-		send_callinfo(sub);
+		send_callinfo(sub, connected_id);
 		transmit_lamp_indication(d, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
 		transmit_ringer_mode(d, SKINNY_RING_INSIDE);
 		transmit_activatecallplane(d, l);
@@ -5809,11 +5834,17 @@
 		sub->substate = SUBSTATE_RINGIN;
 		break;
 	case SUBSTATE_CALLWAIT:
+		connected_id = ast_channel_connected_effective_id(c);
+		if ((ast_party_id_presentation(&connected_id) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
+			fromnum = S_COR(connected_id.number.valid, connected_id.number.str, "Unknown");
+		} else {
+			fromnum = "Unknown";
+		}
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_RINGIN);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_CALLWAIT);
 		transmit_selectsoftkeys(d, l->instance, sub->callid, KEYDEF_RINGIN, KEYMASK_ALL);
 		send_displaypromptstatus(d, OCTAL_CALLWAITING, "", 0, l->instance, sub->callid);
-		send_callinfo(sub);
+		send_callinfo(sub, connected_id);
 		transmit_lamp_indication(d, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
 		transmit_start_tone(d, SKINNY_CALLWAITTONE, l->instance, sub->callid);
 
@@ -5832,7 +5863,6 @@
 		transmit_ringer_mode(d, SKINNY_RING_OFF);
 		transmit_activatecallplane(d, l);
 		transmit_stop_tone(d, l->instance, sub->callid);
-		send_callinfo(sub);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_CONNECTED);
 		send_displaypromptstatus(d, OCTAL_CONNECTED, "", 0, l->instance, sub->callid);
 		transmit_selectsoftkeys(d, l->instance, sub->callid, KEYDEF_CONNECTED, KEYMASK_ALL);
@@ -5866,7 +5896,6 @@
 		if (!d->earlyrtp) {
 			transmit_start_tone(d, SKINNY_BUSYTONE, l->instance, sub->callid);
 		}
-		send_callinfo(sub);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_BUSY);
 		send_displaypromptstatus(d, OCTAL_BUSY, "", 0, l->instance, sub->callid);
 		sub->substate = SUBSTATE_BUSY;
@@ -5880,7 +5909,6 @@
 		if (!d->earlyrtp) {
 			transmit_start_tone(d, SKINNY_REORDER, l->instance, sub->callid);
 		}
-		send_callinfo(sub);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_CONGESTION);
 		send_displaypromptstatus(d, "Congestion", "", 0, l->instance, sub->callid);
 		sub->substate = SUBSTATE_CONGESTION;
@@ -5894,7 +5922,6 @@
 		if (!d->earlyrtp) {
 			transmit_start_tone(d, SKINNY_ALERT, l->instance, sub->callid);
 		}
-		send_callinfo(sub);
 		transmit_callstate(d, l->instance, sub->callid, SKINNY_PROGRESS);
 		send_displaypromptstatus(d, "Call Progress", "", 0, l->instance, sub->callid);
 		sub->substate = SUBSTATE_PROGRESS;
