{"id":443,"date":"2012-08-30T01:00:00","date_gmt":"2012-08-29T23:00:00","guid":{"rendered":"https:\/\/www.fussylogic.co.uk\/blog\/?p=443"},"modified":"2013-06-26T11:53:42","modified_gmt":"2013-06-26T10:53:42","slug":"asterisk-for-a-small-business-ii","status":"publish","type":"post","link":"https:\/\/www.fussylogic.co.uk\/blog\/?p=443","title":{"rendered":"Asterisk For a Small Business (II)"},"content":{"rendered":"<p>Last time we discussed registering multiple trunk lines from a provider using our Asterisk server. As yet, we have no way of making calls, nor any device to receive incoming calls on. Our two trunks are, at the moment, pretty useless.<\/p>\n<p>This time then we\u00e2\u20ac\u2122ll talk about how to configure some local endpoints. These are the other side of the coin we\u00e2\u20ac\u2122ve already seen. When we defined our trunks we specified how to register ourselves with our SIP provider. For locally connected devices we are the provider and we expect them to register with us.<\/p>\n<p>The broad strokes are exactly the same, we will make a template endpoint describing the SIP device connecting to us, then inherit that template and provide some device-specific settings. We\u00e2\u20ac\u2122ll talk, here, only about SIP devices, but be aware that Asterisk supports other device types as well. Let\u00e2\u20ac\u2122s first use a template (note the \u00e2\u20ac\u0153(!)\u00e2\u20ac\u009d) to describe a locally-connected device:<\/p>\n<pre><code>[user](!)\n    type=friend\n    ; address is dhcp assigned, so we can&#39;t match by host because we don&#39;t know it.\n    ; host=dynamic means we allow the device to register with us.\n    host=dynamic\n    ; Can only talk directly if not behind NAT (rename to directmedia)\n    canreinvite=nonat\n    ; regularly poll the device to ensure connectivity (shows &#39;OK&#39; instead of &#39;unmonitored&#39;\n    ; in &#39;sip show peers&#39;)\n    qualify=yes\n    ; Where to direct SUBSCRIBE requests\n    subscribecontext = internal-extensions\n    ; Keep track of calls-in-progress to this device, and stop at 2\n    callcounter = yes\n    busylevel = 2\n    ; Help the device know what to dial to get voicemail\n    vmexten = voicemail<\/code><\/pre>\n<p>The last four options will be important for us later, simply accept them as they are for now. The two key options are \u00e2\u20ac\u0153<code>type=friend<\/code>\u00e2\u20ac\u009d and \u00e2\u20ac\u0153<code>host=dynamic<\/code>\u00e2\u20ac\u009d. Defining the endpoint as a friend makes it both a peer and a user. We have already seen <code>type=peer<\/code> in our trunk endpoint definitions, peers define how incoming calls are matched. Being a user as well (which is what <code>friend<\/code> does requires that the endpoint register with us). Then <code>host=dynamic<\/code> causes the IP address of the endpoint to be set when the endpoint registers.<\/p>\n<p>The simplest devices to set up are softphones. I\u00e2\u20ac\u2122ll use the Android softphone, <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.csipsimple&amp;hl=en\">CSipSimple<\/a> for now as an example, but you\u00e2\u20ac\u2122ll find that whatever device you use will be very similar. First a template to describe the device capabilities.<\/p>\n<pre><code>[csipsimple](!)\n    qualify=5000\n    disallow=all\n    allow=ulaw\n    allow=g726\n    allow=gsm\n    dtmfmode=rfc2833<\/code><\/pre>\n<p>Essentially: codecs and DTMF mode. Set them to suit what the phone supports.<\/p>\n<p>Now we create non-template entries to configure the phones themselves.<\/p>\n<pre><code>[andyp](user,csipsimple)\n    defaultuser=andyp\n    secret=make_up_a_secret1\n    mailbox=andyp@default\n    callerid=&quot;Andy (android)&quot; &lt;2100&gt;\n    context=internal-residential\n\n[wife](user,csipsimple)\n    defaultuser=wife\n    secret=make_up_a_secret2\n    callerid=&quot;Wife (android)&quot; &lt;2101&gt;\n    context=internal-residential\n    mailbox=wife@default<\/code><\/pre>\n<p><code>defaultuser<\/code> and <code>secret<\/code> are the key options. They are what enable the endpoint to identify itself to us. <code>callerid<\/code> is just stored, the number doesn\u00e2\u20ac\u2122t signify anything to Asterisk. We\u00e2\u20ac\u2122ll come back to the <code>mailbox<\/code> and <code>context<\/code> later.<\/p>\n<p>Save this <code>sip.conf<\/code> and return to the command line interface.<\/p>\n<pre><code>$ asterisk -r\nhostname*CLI&gt; reload\nhostname*CLI&gt; sip show users\nUsername                   Secret           Accountcode  Def.Context ACL  ForcerPort\nandyp                      make_up_a_secre               internal-re No   No\nwife                       make_up_a_secre               internal-re No   No<\/code><\/pre>\n<p>Our use of <code>friend<\/code> instead of <code>peer<\/code> for the two local endpoints sets up these two user accounts. But <code>friend<\/code>s are <code>peer<\/code>s as well in Asterisk.<\/p>\n<pre><code>hostname*CLI&gt; sip show peers\nName\/username              Host           Dyn Forcerport ACL Port  Status     \nandyp\/andyp                192.168.1.82    D                       OK (100 ms)\nwife\/wife                  (Unspecified)   D   0                   UNKNOWN    \nvoiptalkOFFICE\/222222222   77.240.48.94        N             5060  Unmonitored\nvoiptalkRESIDENTIAL\/11111  77.240.48.94        N             5060  Unmonitored\n4 sip peers [Monitored: 1 online, 1 offline Unmonitored: 2 online, 0 offline]<\/code><\/pre>\n<p>Our two additional peers exist for the two local endpoints, one hasn\u00e2\u20ac\u2122t registered with the server so is listed as \u00e2\u20ac\u0153UNKNOWN\u00e2\u20ac\u009d status. The other is 100ms of latency away, but is \u00e2\u20ac\u0153OK\u00e2\u20ac\u009d.<\/p>\n<p>It should be clear now what the three lists show.<\/p>\n<ul>\n<li>\u00e2\u20ac\u0153<code>sip show registry<\/code>\u00e2\u20ac\u009d gives a list of SIP servers our server registers <em>to<\/em>. It will show the same number of items regardless of whether the registration was successful (although in our example last time, we saw the successful \u00e2\u20ac\u0153Registered\u00e2\u20ac\u009d state), one entry per \u00e2\u20ac\u0153<code>callbackextension<\/code>\u00e2\u20ac\u009d.<\/li>\n<li>\u00e2\u20ac\u0153<code>sip show users<\/code>\u00e2\u20ac\u009d gives a list of user accounts that can register <em>with<\/em> our server. It will show the same number of items regardless of how many are actually registered with us right now.<\/li>\n<li>\u00e2\u20ac\u0153<code>sip show peers<\/code>\u00e2\u20ac\u009d shows us all our peers and their status. Any endpoint that we expect to make calls to us must be in this list. It is this list that Asterisk checks incoming calls against to map to an endpoint definition.<\/li>\n<\/ul>\n<p>Should you wish to, you can buy analogue telephone adapters (ATA) and connect them to your network. I\u00e2\u20ac\u2122ve got a (now discontinued annoyingly, it\u00e2\u20ac\u2122s very good) HandyTone 386 from Grandstream which has two FXS ports on it.<\/p>\n<pre><code>[ht386](!)\n    disallow=all\n    allow=ulaw\n    allow=alaw\n    allow=g726\n\n[handytone1](user,ht386)\n    secret=handytonesecret1\n    callerid=&quot;Residential&quot; &lt;2102&gt;\n    context=internal-residential\n    mailbox=household@default\n[handytone2](user,ht386)\n    secret=handytonesecret2\n    callerid=&quot;Office&quot; &lt;2103&gt;\n    context=internal-business\n    mailbox=business@default<\/code><\/pre>\n<p>With these in place we now have four local extensions to play with.<\/p>\n<pre><code>hostname*CLI&gt; reload\nhostname*CLI&gt; sip show peers\nName\/username              Host           Dyn Forcerport ACL Port  Status     \nandyp\/andyp                192.168.1.82    D                       OK (100 ms)\nwife\/wife                  (Unspecified)   D   0                   UNKNOWN    \nhandytone1\/handytone1      192.168.1.10    D                 5060  OK (5 ms)\nhandytone2\/handytone2      192.168.1.10    D                 5062  OK (6 ms)\nvoiptalkOFFICE\/222222222   77.240.48.94        N             5060  Unmonitored\nvoiptalkRESIDENTIAL\/11111  77.240.48.94        N             5060  Unmonitored\n6 sip peers [Monitored: 3 online, 1 offline Unmonitored: 2 online, 0 offline]<\/code><\/pre>\n<p>Now we have trunks and extensions defined but we still don\u00e2\u20ac\u2122t have a phone system. Next time we\u00e2\u20ac\u2122ll look at joining our endpoints up under our control.<\/p>\n<p><a href=\"?p=441\">asterisk1<\/a> <a href=\"?p=443\">asterisk2<\/a> <a href=\"?p=445\">asterisk3<\/a> <a href=\"?p=447\">asterisk4<\/a> <a href=\"?p=449\">asterisk5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time we discussed registering multiple trunk lines from a provider using our Asterisk server. As yet, we have no way of making calls, nor any device to receive incoming calls on. Our two trunks are, at the moment, pretty useless. This time then we\u00e2\u20ac\u2122ll talk about how to configure some local endpoints. These are\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.fussylogic.co.uk\/blog\/?p=443\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[31,6],"_links":{"self":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/443"}],"collection":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=443"}],"version-history":[{"count":11,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":1086,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/443\/revisions\/1086"}],"wp:attachment":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}