--- channels/sip/include/sip.h	2011-12-06 18:05:05.000000000 +0100
+++ channels/sip/include/sip.h	2012-03-06 13:52:39.000000000 +0100
@@ -346,6 +346,7 @@
 #define SIP_PAGE2_VIDEOSUPPORT_ALWAYS       (1 << 27)   /*!< DP: Always set up video, even if endpoints don't support it */
 #define SIP_PAGE2_HAVEPEERCONTEXT           (1 << 28)   /*< Are we associated with a configured peer context? */
 #define SIP_PAGE2_USE_SRTP                  (1 << 29)   /*!< DP: Whether we should offer (only)  SRTP */
+#define SIP_PAGE2_FROM_ANONYMOUS 	    (1 << 30) /*!< Use anonymous@anonymous.invalid in FROM with rpid */
 
 #define SIP_PAGE2_FLAGS_TO_COPY \
 	(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \
@@ -353,7 +354,7 @@
 	SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \
 	SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | SIP_PAGE2_PREFERRED_CODEC | \
 	SIP_PAGE2_RPID_IMMEDIATE | SIP_PAGE2_RPID_UPDATE | SIP_PAGE2_SYMMETRICRTP |\
-	SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP)
+	SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP | SIP_PAGE2_FROM_ANONYMOUS)
 
 
 #define SIP_PAGE3_SNOM_AOC               (1 << 0)  /*!< DPG: Allow snom aoc messages */

--- channels/chan_sip.c	2012-02-24 00:30:47.000000000 +0100
+++ channels/chan_sip.c	2012-03-06 14:10:46.000000000 +0100
@ -10739,7 +10739,6 @@
 	const char *fromdomain;
 	const char *privacy = NULL;
 	const char *screen = NULL;
-	const char *anonymous_string = "\"Anonymous\" <sip:anonymous@anonymous.invalid>";
 
 	if (!ast_test_flag(&p->flags[0], SIP_SENDRPID)) {
 		return 0;
@@ -10764,12 +10763,13 @@
 	lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), 0);
 
 	if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) {
+		ast_str_set(&tmp, -1, "\"%s\" <sip:%s@%s>", lid_name, lid_num, fromdomain);
+		add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp));
 		if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
-			ast_str_set(&tmp, -1, "%s", anonymous_string);
+			add_header(req, "Privacy", "id");
 		} else {
-			ast_str_set(&tmp, -1, "\"%s\" <sip:%s@%s>", lid_name, lid_num, fromdomain);
+			add_header(req, "Privacy", "none");
 		}
-		add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp));
 	} else {
 		ast_str_set(&tmp, -1, "\"%s\" <sip:%s@%s>;party=%s", lid_name, lid_num, fromdomain, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "calling" : "called");
 
@@ -11840,6 +11840,14 @@
 			l = CALLERID_UNKNOWN;
 			n = l;
 			d = FROMDOMAIN_INVALID;
+		} else if (ast_test_flag(&p->flags[1], SIP_PAGE2_FROM_ANONYMOUS)) {
+			/* if we are want to send anonymous@anonymous.invalid in FROM tag while sending RPID */
+			l = CALLERID_UNKNOWN;
+			n = l;
+			d = FROMDOMAIN_INVALID;
+		} else {
+			l = p->owner->connected.id.number.valid ? p->owner->connected.id.number.str : NULL;
+			n = p->owner->connected.id.name.valid ? p->owner->connected.id.name.str : NULL;
 		}
 	}
 
@@ -26506,10 +26514,18 @@
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID);
 	} else if (!strcasecmp(v->name, "sendrpid")) {
 		ast_set_flag(&mask[0], SIP_SENDRPID);
-		if (!strcasecmp(v->value, "pai")) {
+		if ((!strcasecmp(v->value, "pai")) || (!strcasecmp(v->value, "pai,trusted"))) {
 			ast_set_flag(&flags[0], SIP_SENDRPID_PAI);
-		} else if (!strcasecmp(v->value, "rpid")) {
-			ast_set_flag(&flags[0], SIP_SENDRPID_RPID);
+		} else if (!strcasecmp(v->value, "pai,untrusted")) {
+			ast_set_flag(&flags[0], SIP_SENDRPID_PAI);
+           ast_set_flag(&mask[1], SIP_PAGE2_FROM_ANONYMOUS);
+			ast_set_flag(&flags[1], SIP_PAGE2_FROM_ANONYMOUS);
+ 		} else if ((!strcasecmp(v->value, "rpid")) || (!strcasecmp(v->value, "rpid,trusted"))) {
+       	ast_set_flag(&flags[0], SIP_SENDRPID_RPID);
+		} else if (!strcasecmp(v->value, "rpid,untrusted")) {
+ 			ast_set_flag(&flags[0], SIP_SENDRPID_RPID);
+			ast_set_flag(&mask[1], SIP_PAGE2_FROM_ANONYMOUS);
+			ast_set_flag(&flags[1], SIP_PAGE2_FROM_ANONYMOUS);
 		} else if (ast_true(v->value)) {
 			ast_set_flag(&flags[0], SIP_SENDRPID_RPID);
 		}

--- configs/sip.conf.sample	2011-12-18 19:27:16.000000000 +0100
+++ configs/sip.conf.sample	2012-03-06 23:06:27.000000000 +0100
@@ -321,11 +321,19 @@
 ;relaxdtmf=yes                  ; Relax dtmf handling
 ;trustrpid = no                 ; If Remote-Party-ID should be trusted
 ;sendrpid = yes                 ; If Remote-Party-ID should be sent (defaults to no)
-;sendrpid = rpid                ; Use the "Remote-Party-ID" header
+;sendrpid = rpid,trusted        ; Use the "Remote-Party-ID" header
                                 ; to send the identity of the remote party
                                 ; This is identical to sendrpid=yes
-;sendrpid = pai                 ; Use the "P-Asserted-Identity" header
+;sendrpid = rpid,untrusted	; Use the "Remote-Party-ID" header
                                 ; to send the identity of the remote party
+				; When call presentation is prohibited the FROM header is changed to
+				; anonymous@anonymous.invalid
+;sendrpid = pai,trusted         ; Use the "P-Asserted-Identity" header
+                                ; to send the identity of the remote party
+;sendrpid = pai,untrusted       ; Use the "P-Asserted-Identity" header
+                                ; to send the identity of the remote party
+				; When call presentation is prohibited the FROM header is changed to
+                                ; anonymous@anonymous.invalid
 ;rpid_update = no               ; In certain cases, the only method by which a connected line
                                 ; change may be immediately transmitted is with a SIP UPDATE request.
                                 ; If communicating with another Asterisk server, and you wish to be able