# MikoPBX and FreePBX (PJSIP)

## Creating a Provider on MikoPBX

1. In MikoPBX, go to **"Routing"** → **"Telephony Providers"**:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FVYiyVJv2nPxA6RmMSve3%2FTelephonyProvidersSection.jpg?alt=media&#x26;token=17a501df-c2ec-4e8d-bb51-799659b21774" alt=""><figcaption><p>"Telephony Providers" section</p></figcaption></figure>

2. Add a new SIP provider by clicking **"Connect SIP"**:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F4xUnTYvjCVdaMxKqlrud%2FcoonectSIPbtn.jpg?alt=media&#x26;token=ec778166-78b4-42d4-96a8-8469244bb4bc" alt=""><figcaption><p>"Connect SIP" button</p></figcaption></figure>

3. Fill in the following parameters:

* **Provider Name** – any name
* **Account Type** – Incoming Registration

Copy the "**Username"** and "**Password"**; you will need them later.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FjXoxU2bxEloQRBbexm5X%2FproviderMikoPBXParameters.jpg?alt=media&#x26;token=7c47645c-f077-49f6-bb64-060df17ee512" alt=""><figcaption><p>Provider parameters (MikoPBX)</p></figcaption></figure>

## Creating a Trunk on FreePBX

1. In the FreePBX interface, go to **"Connectivity"** → **"Trunks"**:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FRG9A2QnPMyn2McVLnqdM%2FTrunksFreePBX.jpg?alt=media&#x26;token=eb665b92-8569-4388-be18-e0be4e467067" alt=""><figcaption><p>"Trunks" section</p></figcaption></figure>

2. Add a new trunk of type **"chan\_pjsip"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F4zgdNqCTPH0HqmIkAYvn%2FnewTrunkFreePBX.jpg?alt=media&#x26;token=e41e3fc9-5a37-4203-b11e-ce6c075b5207" alt=""><figcaption><p>Adding a new trunk</p></figcaption></figure>

3. Insert the MikoPBX provider’s login into the **"Trunk Name"** field:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FpFq12zlglvdwuYpBFKSi%2FtrunkNameFreePBX.jpg?alt=media&#x26;token=e9f8bc98-6789-47c4-9c6f-dd79bb96d704" alt=""><figcaption><p>"Trunk Name<strong>"</strong> field</p></figcaption></figure>

4. Go to **"pjsip Settings"** → **"Advanced"**:

* **From User** – your MikoPBX provider login
* **Trust RPID/PAI** – "yes"
* **Send RPID/PAI** – "Send Remote-Party-ID header"

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F8KATQEUZjFe8wwAFpRz2%2FadditionalParametersTrunkFreePBX.jpg?alt=media&#x26;token=c720419d-de9d-498a-af45-8d258d787e41" alt=""><figcaption><p>Advanced parameters of the trunk</p></figcaption></figure>

5. On the **"Dialed Number Manipulation Rules"** tab, define your dial patterns

Save the changes.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FZkZgU8KJvb1qjIlN2s0v%2FnumberTe%2Cplates.jpg?alt=media&#x26;token=e1f7eccd-8e0c-4115-8131-8ce5cb3a845a" alt=""><figcaption><p>Dialed Number Manipulation Rules</p></figcaption></figure>

## Registration Variants

Next, choose **one** of the two registration methods:

### **FreePBX Registers on MikoPBX**

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F7Oc5Xf41RpE0gMWVUe9x%2FFreePBXMikoPBXSample.jpg?alt=media&#x26;token=d6303b1b-cfa2-4721-a493-7c1012305777" alt=""><figcaption><p>Registration Sample 1</p></figcaption></figure>

### **MikoPBX Registers on FreePBX**

Set a password (**complex**, arbitrary). It must be the same on both MikoPBX and FreePBX.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FhekMkQgoytbBPdIY8QQ9%2Fsample2.jpg?alt=media&#x26;token=0ef281f5-2609-4e60-9b56-53f2d0dc4603" alt=""><figcaption><p>Registration Sample 2</p></figcaption></figure>

In the MikoPBX “advanced settings” of your provider, under **"Additional Parameters,"** include:

```
[endpoint]
trust_id_inbound=yes
send_rpid=yes
```

Save and apply the changes.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FN9Z3dDsvu1qe3eAwcbj7%2FadvancedOptionsProviderMikoPBX.jpg?alt=media&#x26;token=0cd050b3-f19b-4057-8e6e-b452790e61dd" alt=""><figcaption><p>Advanced Options of provider</p></figcaption></figure>

## Routing Configuration

1. Define an outbound route ([“Outbound Routing” article](https://docs.mikopbx.com/mikopbx/english/manual/routing/outbound-routing)) in MikoPBX:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FAVmfou5YK9gmroaOuxWk%2FOutgoingTemplateForFreePBXusaSample.jpg?alt=media&#x26;token=6245a327-b059-4548-b09d-7988dd706c85" alt=""><figcaption><p>Outgoing routing template MikoPBX</p></figcaption></figure>

2. Define an inbound route ([“Incoming Routing” article](https://docs.mikopbx.com/mikopbx/english/manual/routing/incoming-routing)) in MikoPBX:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FJ1iIwnHp2m64Pqojpjgr%2FinboundMikoPBX.jpg?alt=media&#x26;token=85f175ef-349a-4394-8ab2-fd4565a55e0f" alt=""><figcaption><p>Inbound routing template MikoPBX</p></figcaption></figure>

If necessary, define a separate route for each DID to direct calls to the correct destination (e.g., if a FreePBX user dials **202**, route it to extension **202** on MikoPBX):

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FptISNVh8IgNrEoMzJVV4%2FinboundMikoPBXindividualDID.jpg?alt=media&#x26;token=c4a67745-6d97-4258-beae-51a8f532f8ce" alt=""><figcaption><p>Inbound routing template (Individual DID configuring)</p></figcaption></figure>

3. Go to **"Connectivity"** → **"Inbound Routes"** in FreePBX and define an inbound route:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FEm8LqKCo0XlDkyGQxGjC%2FincomingFromFreePBX.jpg?alt=media&#x26;token=cbe6e949-f5fe-48c5-8844-ab97ea5d3f6f" alt=""><figcaption><p>Inbound routing template FreePBX</p></figcaption></figure>

4. Go to **"Connectivity"** → **"Outbound Routes"** in FreePBX and define an outbound route:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F41HxAUuBU1qrPjA8aP88%2FoutgoingFromFreePBX.jpg?alt=media&#x26;token=5702ffd6-347d-4b1a-9b06-460977fc2aa8" alt=""><figcaption><p>Outbound routing template FreePBX</p></figcaption></figure>

## Subscriber Statuses

Sometimes users on one PBX need to see the statuses of users on the other PBX, for example when using BLF. To configure statuses:

### MikoPBX

1. In the "[System File Customization](https://docs.mikopbx.com/mikopbx/english/manual/system/custom-files)" section, add the following text to the end of **"extensions.conf"** on the first PBX:

```php
[internal-hints]
exten => 301,hint,PJSIP/301
exten => 303,hint,PJSIP/303
exten => 302,hint,PJSIP/302
```

List all internal extensions configured on FreePBX.

2. For **each PBX**, in the "System file customization" section, add the following text to the end of **"pjsip.conf"**:

```php
[SIP-TRUNK-41C1B8B4-devicestate]
type=outbound-publish
server_uri=sip:SIP-TRUNK-41C1B8B4@172.16.156.216:5060
event=asterisk-devicestate

[SIP-TRUNK-41C1B8B4]
type=asterisk-publication
devicestate_publish=SIP-TRUNK-41C1B8B4-devicestate
device_state=yes

[SIP-TRUNK-41C1B8B4]
type=inbound-publication
event_asterisk-devicestate=SIP-TRUNK-41C1B8B4
```

{% hint style="success" %}
Replace **"SIP-TRUNK-41C1B8B4"** with your MikoPBX provider ID and **"172.16.156.216"** with the FreePBX address as appropriate.
{% endhint %}

### FreePBX

1. Use the **"Config Edit"** module to edit files.
2. In **"extensions\_custom.conf,"** add all of MikoPBX’s internal extensions:

```php
[mikopbx-hints]
exten => 201,hint,PJSIP/201
exten => 202,hint,PJSIP/202
```

3. In **"pjsip\_custom.conf,"** add:

```php
[SIP-TRUNK-41C1B8B4-devicestate]
type=outbound-publish
server_uri=sip:SIP-TRUNK-41C1B8B4@172.16.156.223:5060
event=asterisk-devicestate
outbound_auth=SIP-TRUNK-41C1B8B4

[SIP-TRUNK-41C1B8B4]
type=asterisk-publication
devicestate_publish=SIP-TRUNK-41C1B8B4-devicestate
device_state=yes
device_state_filter=^PJSIP/

[SIP-TRUNK-41C1B8B4]
type=inbound-publication
event_asterisk-devicestate=SIP-TRUNK-41C1B8B4
```

{% hint style="success" %}
Replace **"SIP-TRUNK-41C1B8B4"** with your MikoPBX provider ID and **"172.16.156.216"** with the FreePBX address, as needed.
{% endhint %}

{% hint style="danger" %}
The **outbound\_auth=SIP-TRUNK-41C1B8B4** option applies only if FreePBX registers on MikoPBX. Status sharing was tested only under this registration scenario.
{% endhint %}
