O bloqueio de chamadas a cobrar no Brasil costuma ser uma chatice. No caso das operadoras temos as que querem ganhar $$$ pra bloquear e as que tem uma tremenda má vontade em faze-lo (EMBRAHELL em Belo Horizonte).

Utilizando placas Digium, costuma-se dizer que só se bloqueia chamadas a cobrar no Asterisk utilizando sinalização MFC/R2 com Unicall, que pode ser mais problemático que simplesmente pagar pelas chamadas a cobrar que entram. Bom, até hoje era assim.

A solucao, pelo menos aqui, apareceu magicamente quando investigava mensagens do tipo:


NOTICE[13896] chan_zap.c: PRI got event: HDLC Bad FCS (8) on Primary D-channel of span 1
NOTICE[15470] chan_zap.c: PRI got event: HDLC Abort (6) on Primary D-channel of span 1

um “asterisk*CLI> pri debug span 1” revelou o seguinte bloco no log:


< Protocol Discriminator: Q.931 (8) len=41
< Call Ref: len= 2 (reference 6186/0x182A) (Originator)
< Message type: SETUP (5)
< [a1]
< Sending Complete (len= 1)
< [55 55 55 55 55]
< Bearer Capability (len= 5) [ Ext: 1 Q.931 Std: 0 Info transfer capability: Speech (0)
< Ext: 1 Trans mode/rate: 64kbps, circuit-mode (16)
< Ext: 1 User information layer 1: A-Law (35)
< [55 55 55 55 55]
< Channel ID (len= 5) [ Ext: 1 IntID: Implicit PRI Spare: 0 Preferred Dchan: 0
< ChanSel: Reserved
< Ext: 1 Coding: 0 Number Specified Channel Type: 3
< Ext: 1 Channel: 1 ]
< [55 55 55 55]
< Progress Indicator (len= 4) [ Ext: 1 Coding: CCITT (ITU) standard (0) 0: 0 Location: Public network serving the local user (2)
< Ext: 1 Progress Description: Calling equipment is non-ISDN. (3) ]
< [55 55 55 55 55 55 55 55 55 55 55 55 55 55]
< Calling Number (len=14) [ Ext: 0 TON: National Number (2) NPI: ISDN/Telephony Numbering Plan (E.164/E.163) (1)
< Presentation: Presentation allowed of network provided number (3) '3155555555' ]
< [55 55 55 55 55 55 55]
< Called Number (len= 7) [ Ext: 1 TON: Subscriber Number (4) NPI: ISDN/Telephony Numbering Plan (E.164/E.163) (1) '0000' ]
-- Making new call for cr 6186
-- Processing Q.931 Call Setup
-- Processing IE 161 (cs0, Sending Complete)
-- Processing IE 4 (cs0, Bearer Capability)
-- Processing IE 24 (cs0, Channel Identification)
-- Processing IE 30 (cs0, Progress Indicator)
-- Processing IE 108 (cs0, Calling Party Number)
-- Processing IE 112 (cs0, Called Party Number)
q931.c:3308 q931_receive: call 6186 on channel 1 enters state 6 (Call Present)
q931.c:2582 q931_call_proceeding: call 6186 on channel 1 enters state 9 (Incoming Call Proceeding)

Interessante, pensei. E se eu discasse à cobrar, mudaria alguma coisa?


< Protocol Discriminator: Q.931 (8) len=44
< Call Ref: len= 2 (reference 6192/0x1830) (Originator)
< Message type: SETUP (5)
< [a1]
< Sending Complete (len= 1)
< [55 55 55 55 55]
< Bearer Capability (len= 5) [ Ext: 1 Q.931 Std: 0 Info transfer capability: Speech (0)
< Ext: 1 Trans mode/rate: 64kbps, circuit-mode (16)
< Ext: 1 User information layer 1: A-Law (35)
< [55 55 55 55 55]
< Channel ID (len= 5) [ Ext: 1 IntID: Implicit PRI Spare: 0 Preferred Dchan: 0
< ChanSel: Reserved
< Ext: 1 Coding: 0 Number Specified Channel Type: 3
< Ext: 1 Channel: 2 ]
< [55 55 55 55]
< Progress Indicator (len= 4) [ Ext: 1 Coding: CCITT (ITU) standard (0) 0: 0 Location: Public network serving the local user (2)
< Ext: 1 Progress Description: Calling equipment is non-ISDN. (3) ]
< [55 55 55]
< IE: Reverse Charging Indication (len = 3)
< [55 55 55 55 55 55 55 55 55 55 55 55 55 55]
< Calling Number (len=14) [ Ext: 0 TON: National Number (2) NPI: ISDN/Telephony Numbering Plan (E.164/E.163) (1)
< Presentation: Presentation allowed of network provided number (3) '5555555555' ]
< [55 55 55 55 55 55 55]
< Called Number (len= 7) [ Ext: 1 TON: Subscriber Number (4) NPI: ISDN/Telephony Numbering Plan (E.164/E.163) (1) '5555' ]
-- Making new call for cr 6192
-- Processing Q.931 Call Setup
-- Processing IE 161 (cs0, Sending Complete)
-- Processing IE 4 (cs0, Bearer Capability)
-- Processing IE 24 (cs0, Channel Identification)
-- Processing IE 30 (cs0, Progress Indicator)
-- Processing IE 74 (cs0, Reverse Charging Indication)
-- Processing IE 108 (cs0, Calling Party Number)
-- Processing IE 112 (cs0, Called Party Number)
q931.c:3308 q931_receive: call 6192 on channel 2 enters state 6 (Call Present)
q931.c:2582 q931_call_proceeding: call 6192 on channel 2 enters state 9 (Incoming Call Proceeding)

E nao é que mudou mesmo? olha o safado ali em cima: “Reverse Charging Indication”

Um rapido “grep ‘Reverse Charging Indication’ * -r” no diretorio do source da libpri mostrou que o q931.c teria que ser modificado.

Meia hora de confusao e varios segfault do asterisk depois (afinal, eramos um cego guiando outro) usamos nosso Super Ninja C Skillz e demos um “sleep(10)” no codigo. Suficiente pra dar timeout sabemos lá aonde e matar a chamada.

O seguinte patch é capaz de bloquear com 100% de acerto todas as chamadas a cobrar numa E1 ISDN.


*** q931.c    2007-06-19 15:23:36.000000000 -0300
--- q931.mod    2008-08-21 23:54:10.000000000 -0300
***************
*** 2355,2360 ****
--- 2355,2361 ----
int full_ie = Q931_FULL_IE(codeset, ie->ie);
if (pri->debug & PRI_DEBUG_Q931_STATE)
pri_message(pri, "-- Processing IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie));
+         if (strcmp(ie2str(full_ie), "Reverse Charging Indication") == 0) sleep(10);
for (x=0;x<sizeof(ies) / sizeof(ies[0]);x++) {
if (full_ie == ies[x].ie) {
if (ies[x].receive)

take diz muthafocka!