I would be surprised if someone told me they don't get marketing calls. There are many ways to mitigate them, yet they are still here. Implementing the STIR/SHAKEN protocol and rejecting all the non-signed INVITES to your PBX is the best way to minimize a suspicious call. However, at this point, not everybody is signing the calls; therefore, you could have false positives (blocking legitimate calls).
In this article, I will explain how to implement the two recommendations from the CRTC for those PBXes that are not offering an opt-in call filtering system.
Block all non-North American Numbering Plan numbers
North American numbers are not random numbers. Yes, they are 11 digits (10 if you don't count the leading one), but they have a syntax. The rules are these:
- NPA (Numbering Plan Area Code) - Allowed ranges: [2–9] for the first digit, and [0-9] for the second and third digits. When the second and third digits of an area code are the same, that code is called an easily recognizable code (ERC). ERCs designate special services; e.g., 888 for toll-free service. The NANP does not assign area codes with 9 as the second digit.
- NXX (Central Office) - Allowed ranges: [2–9] for the first digit, and [0–9] for both the second and third digits (however, the third digit cannot be "1" if the second digit is also "1").
- xxxx (Subscriber Number) -[0–9] for each of the four digits.
With this in mind, the following dialplan will block any non-compliant NANP.
<extension name="basic-filtering-1" continue="true" uuid="28b12380-dcc0-4291-8192-449fd13386c3">
<condition field="caller_id_number" expression="^\+?\d{10,11}$">
<action application="set" data="is_nanpa=${regex( m:~${caller_id_number}~^(\+1|1)?([2-9][0-9]{2})([2-9](?!11)[0-9]{2})([0-9]{4})$)}" inline="true"/>
</condition>
<condition field="${is_nanpa}" expression="false">
<action application="hangup" data="CALL_REJECTED"/>
</condition>
</extension>
Block all the calls if the Caller ID exceeds 15 digits
This is an easy one. The FreeSWITCH dialplan should be as follows:
<extension name="basic-filtering-2" continue="false" uuid="7337d625-76c7-4ade-8b08-ae87778f579b">
<condition field="caller_id_number" expression="^\+?\d{16,}$">
<action application="export" data="call_direction=inbound" inline="true"/>
<action application="set" data="domain_uuid=231657cc-e5cb-48ba-b265-e0b7383970c4" inline="true"/>
<action application="set" data="domain_name=pbx.to-call.me" inline="true"/>
<action application="hangup" data="CALL_REJECTED"/>
</condition>
</extension>
This is a very basic protection as any telemarketer could be spoofing legitimate phone numbers.
Good luck!