WWW.DUMAIS.IO
ARTICLES
OVERLAY NETWORKS WITH MY SDN CONTROLLERSIMPLE LEARNING SWITCH WITH OPENFLOWINSTALLING KUBERNETES MANUALLYWRITING A HYPERVISOR WITH INTEL VT-X CREATING YOUR OWN LINUX CONTAINERSVIRTIO DRIVER IMPLEMENTATIONNETWORKING IN MY OSESP8266 BASED IRRIGATION CONTROLLERLED STRIP CONTROLLER USING ESP8266.OPENVSWITCH ON SLACKWARESHA256 ASSEMBLY IMPLEMENTATIONPROCESS CONTEXT ID AND THE TLBTHREAD MANAGEMENT IN MY HOBBY OSENABLING MULTI-PROCESSORS IN MY HOBBY OSNEW HOME AUTOMATION SYSTEMINSTALLING AND USING DOCKER ON SLACKWARESYSTEM ON A CHIP EMULATORUSING JSSIP AND ASTERISK TO MAKE A WEBPHONEC++ WEBSOCKET SERVERSIP ATTACK BANNINGBLOCK CACHING AND WRITEBACKBEAGLEBONE BLACK BARE METAL DEVELOPEMENTARM BARE METAL DEVELOPMENTUSING EPOLLMEMORY PAGINGIMPLEMENTING HTTP DIGEST AUTHENTICATIONSTACK FRAME AND THE RED ZONE (X86_64)AVX/SSE AND CONTEXT SWITCHINGHOW TO ANSWER A QUESTION THE SMART WAY.REALTEK 8139 NETWORK CARD DRIVERREST INTERFACE ENGINECISCO 1760 AS AN FXS GATEWAYHOME AUTOMATION SYSTEMEZFLORA IRRIGATION SYSTEMSUMP PUMP MONITORINGBUILDING A HOSTED MAILSERVER SERVICEI AM NOW HOSTING MY OWN DNS AND MAIL SERVERS ON AMAZON EC2DEPLOYING A LAYER3 SWITCH ON MY NETWORKACD SERVER WITH RESIPROCATEC++ JSON LIBRARYIMPLEMENTING YOUR OWN MUTEX WITH CMPXCHGWAKEUPCALL SERVER USING RESIPROCATEFFT ON AMD64CLONING A HARD DRIVECONFIGURING AND USING KVM-QEMUUSING COUCHDBINSTALLING COUCHDB ON SLACKWARENGW100 MY OS AND EDXS/LSENGW100 - MY OSASTERISK FILTER APPLICATIONCISCO ROUTER CONFIGURATIONAASTRA 411 XML APPLICATIONSPA941 PHONEBOOKSPEEDTOUCH 780 DOCUMENTATIONAASTRA CONTACT LIST XML APPLICATIONAVR32 OS FOR NGW100ASTERISK SOUND INJECTION APPLICATIONNGW100 - DIFFERENT PROBLEMS AND SOLUTIONSAASTRA PRIME RATE XML APPLICATIONSPEEDTOUCH 780 CONFIGURATIONUSING COUCHDB WITH PHPAVR32 ASSEMBLY TIPAP7000 AND NGW100 ARCHITECTUREAASTRA WEATHER XML APPLICATIONNGW100 - GETTING STARTEDAASTRA ALI XML APPLICATION

NGW100 - DIFFERENT PROBLEMS AND SOLUTIONS

2012-02-25

AVR32 troubleshooting

In this section, I will describe different problems I ran into. Everytime I spend a lot of time trying to figure why something did not work, I will post the found solutions here.

Illegal opcode with conditional instructions

Everytime I was using "addhi" I got an illegal opcode exception. The worse thing was that I was using addhi inside and exception handler. This is because it seems that my CPU uses architecture revision 1. when looking at the isntruction set reference, you can see that these instructions are meant to be used on revision 2 architecture. It is a shame because I couldn't wait to use those.... oh well.

Unrecoverable exception on scall

Everytime I was using "scall", the "unrecoverable exception" was issued instead of EVBA+0x100. I found out that this is because EVBA was not alligned on a 8kb oundary

Copying to parallel flash using u-boot

The address ranges in the AT49BV642D datasheet are 16bit words! So when they say that the sector 23 resides from 0x80000 up to 0x87FFF, it really means from 0x100000 to 0x107FFF.

ASID field in page table

I could understand from the architecture document that the ASID field in a page table entry (from the TLB) is used by the MMU to match the current process ID. What I could not understand was that the ASID field is matched... against what? Yes it is matched against the processID but where is the current proces ID stored? It is in the TLBEHI register. so the TLBEHI[ASID] field should not only be filled before loading a page in the TLB, it should be loaded ALL the time since it will be used for the comparison as well.

Locking entries in TLB

When setting DLA or ILA in MMUCR, make sure you change DRP or IRP accordingly. If you lock the first entry and leave DRP (or IRP) to 0, you will never be able to write anything in the TLB

INTC not working properly, values written to IPR are read back as zero

Make sure that INTC is enabled in PBBMASK (See power manager)

Comparing a page with buffer on the dataflash always says that the page matches even though it is different

When I was reading a page (using 0x87) , then writting something else to buffer1. A buffer comparison always returned that the pages matched. To fix this, I am now using buffer2 to write and compare. It solves the problem but it doesn't make any sense.

MACB: RBQP increases when receiving frames but descriptor's ownership flag does not change

It is important to load RBQP with a physical address (not virtual address). Descriptors must also be loaded with physical addresses. Also, even if reading descriptors from the P2 segment (uncached memory), it is important to invalidate the cache ("cache r0[0],0b1011").

AASTRA PRIME RATE XML APPLICATION

2012-02-25

Prime rate

I wanted to have a way of seeing the current prime rate of the National Bank Of Canada every day. Instead of having a bookmark or a RSS reader, I figured it might be useful to have that information displayed on the idle screen of my a57i phone. This application is a good example to figure out how to write an Idle screen application. I haved added the url of my application in the "Poll" field under the "Action URI" page. That way, the application is downloaded every 3600 seconds and the idle screen is then refreshed. This application also includes the current outside temperature taken from the ministry of environment webpage.

Download

aastraprimerate.tar

SPEEDTOUCH 780 CONFIGURATION

2012-02-25

The speedtouch 780 is a DSL modem combined with a 4 port managed switch/router, 1 FXO and 2 FXS. One great thing about this modem is that it is possible to telnet on the device and get access to a CLI. Using the CLI, one can achieve great things with this piece of hardware.

The specs will say that the FXO is a "Full-Mode" FXO. I don't know what they mean by that, but I was very disapointed when I used it. The FXO does not register itself with a PBX. Meaning that it is impossible to use it for placing outgoing calls or to receive calls using Asterisk (for example). You can setup a dialplan (in the device) that will allow certain numbers to be dialed directly on the FXO (i.e: 911) using the FXS ONLY! The FXO can also be used as a Fallback (for the FXS only) if registration with the PBX failed. It is then impossible to use the ST780 for PSTN access with Asterisk. For that purpose, I am using a SPA3102

Configuration

This is just a sample of what I have. You will find the things I found to be the most usefull.

DHCP Pool

Before configuring this, make sure no one has a lease. In this example I am adding a pool named LAN_private. The addresses will be assigned on the interface LocalNetwork. Specifying the interface is very usefull when using several VLANs.

:dhcp server lease flush :dhcp server pool config name=LAN_private intf=LocalNetwork poolstart=192.168.1.101 poolend=192.168.1.254 gateway=192.168.1.1 leasetime=21600 primdns=192.168.1.3 secdns=192.168.1.1

VLANs

This was hard to figure out. The way I am setup, I have two different VLANs. One which is the default VLAN (untagged) and the other one is tagged with ID 3. I have a Dell PowerConnect 3348 switch which has 24 port that belong in the untagged VLAN and the other 24 in VLAN3. Traffic comming from/goint to the switch for the untagged VLAN is plugged on ethernet port 1 of the st780. Traffic for VLAN 3 is also connected to ethernet port 1. The trunk comming from the switch thus transports both VLANs. I have two different DHCP pools for each VLAN so that they can be assigned different addresses in two distinct subnets.

I don't fully understand all this. All I know is that it works. I have searched everywhere and only found bits of information about that particular setup. I figured everything out by trying different stuff until it worked and trying to understand how to connect the dots between different setup I saw on other sites. Please feel free to contact me to inform me of any mistake I did here or to give me advices.

; Create vlan #3 named vlan3 :eth vlan add name=vlan3 vid=3 ;Add the OBC interface in vlan3. disabling untagging will prevent the switch from stripping ; off the tag of the incomming frame on that interface. I think that the OBC interface is the interface ; on which the router resides. If you don't add this interface in the VLAN, you won't be able to ping to router. :eth bridge vlan ifadd name=vlan3 intf=OBC untagged=disabled ;Add the ethernet port 1 in the vlan #3. We want to preserve the VLAN tag. Untagged frames will be assigned ; the default VLAN (VLAN ID 0) :eth bridge vlan ifadd name=vlan3 intf=ethport1 untagged=disabled ; Unttaged egress traffic on ethport1 will be tagged with VLAN ID "default" (0) :eth bridge ifconfig intf=ethport1 vlan=default ; Create a new ethernet logical interface :eth ifadd intf=eth_vlan3 ; frames transmitted through this interface will be tagged with vlan3 :eth ifconfig intf=eth_vlan3 dest=bridge vlan=vlan3 ;enable the interface (put it up) :eth ifattach intf=eth_vlan3 ; when using this ip interface, transmit using vlan3 logical ethernet interface. I'm not sure why I have to use the group "lan". ; if I don't use that group, it doesn't work. :ip ifadd intf=ip_vlan3 dest=eth_vlan3 group=lan :ip ifattach intf=ip_vlan3 ; when using this subnet, use vlan3 ip interface. :ip ipadd intf=ip_vlan3 addr=192.168.0.1/24 ; Add a second DHCP pool for the 2nd vlan :dhcp relay add name=relay_vlan3 :dhcp relay ifconfig intf=ip_vlan3 relay=enabled maxhops=4 trusted=disabled :dhcp relay modify name=relay_vlan3 addr =127.0.0.1 intf =ip_vlan3 giaddr =192.168.0.1

I might be wrong here, but this is the way I understand it: When a frame comes in on an ethernet interface, it VLAN ID is looked at and the frame is forwarded to every ethernet port that belongs to that VLAN. When transmitting a packet on the 192.168.0.0 subnet, the IP interface ip_vlan3 will be used. ip_vlan3 uses the logical ethernet interface eth_vlan3. When a frame is transmitted on eth_vlan3, it will be tagged with VLAN vlan3. Since ethport1 is a member of vlan3, the frame will be forwarded on it.

Port Forwarding

This is one of the easyest thing. No explanation needed here

nat mapadd intf=Internet inside_addr=192.168.0.3 inside_port=5060-5062 outside_port=5060-5062

SIP

My st780 is setup to register both FXS ports on my Asterisk PBX.

; Disable the service already provided by the device :connection appconfig application=SIP SIP_ALG=disabled :voice config digitrelay=rfc2833 rtp_portrange=10000-10100 ;FIRST: delete current profiles :voice profile add SIP_URI=username username=username password=your_password voiceport=FXS1 ; 192.168.0.2 is the address of the PBX :voice sip config useragentdomain=192.168.0.2 primproxyaddr=192.168.0.2 primregaddr=192.168.0.2 :service system modify name=VOIP_SIP state=enabled port=5060 ;allow 2000ms between each DTMF before assuming that dialing is completed. :voice fxsport config interdigitOpen=2000 interdigit=2000 ; When a call comes in on the FXO, don't forward it anywhere. You could forward it to one of the FXS, but ; not to your PBX unfortunately :voice fxoport config incfxodest=none ; the voice interface should use the ip interface ip_vlan3 :voice config intf = ip_vlan3 ; any number between 3 and 14 digits long must be forwarded to the PBX without being altered. If VOIP cannot be accessed, (PBX down, power failure, ...) use FXO :voice dialplan add prefix=0-8 defaultport=Voip fallbackport=FXO priority=Low fallback=enabled minimumdigits=3 maximumdigits=14 posofmodify=0 remnumdigits=0 rescan=no action=none ; 911 must be forwarded on the FXO directly :voice dialplan add prefix=911 defaultport=FXO fallbackport=FXO priority=High fallback=enabled minimumdigits=3 maximumdigits=3 posofmodify=0 remnumdigits=0 rescan=no action=none

The other day, my PBX was down. I noticed that every outgoing calls were automatically sent on the FXO instead of the PBX. This is the way I want it (because of the "fallback" option). The odd thing was that incomming calls were not forwarded from the FXO to the FXS. This is one thing I will have to figure out.

USING COUCHDB WITH PHP

2012-02-25

Introduction

Since couchdb provides a REST interface, it is tempting use AJAX to query the database directly to display data on your webpage. This is not always possible though. If my database runs on port 5555 then this means that my webpage will need access to port 5555 on my server. It's not always possible if firewalls are in the way. We know at least that port 80 should always be accessible. For several security reasons too, we might want the CouchDB to be hidden behind the public network and only accessible by the web server internally. Just as we would do with a SQL server.

Code

  • Retrieve a document $h = curl_init("http://server/db1/document1"); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET"); $response = curl_exec($h); $obj = json_decode($response);
  • Create views
    Json file: { "language": "javascript", "views": { "view1": { "map": "function(doc){emit(doc._id,doc);}" }, "view2": { "map": "function(doc){emit(doc._id,doc);}", "reduce": "function (key, values){return null;}" } } } PHP script: $json = file_get_contents("views.json"); $h = curl_init("http://server/db1/_design/designdoc1"); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($h, CURLOPT_POSTFIELDS,$json); curl_setopt($h, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); $response = curl_exec($h);
  • Create doc $obj = array("field1"=>"val1","field2"=>"val2"); $json = json_encode($obj); $h = curl_init("http://server/db1/document1"); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($h, CURLOPT_POSTFIELDS,$json); curl_setopt($h, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); $response = curl_exec($h);
  • Query a view $h = curl_init("http://server/db1/_design/document1/_view/view1?reduce=true&group=true"); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET"); $response = curl_exec($h); $json=json_decode($response);

Retrieving attachments

Let's say we have an attachment that can be reachable at http://couchdbServer/database1/document1/image1.jpg. If "document1" is a blog post that show "image1", it is tempting to put a <img src=database1/document1/image1.jpg > But this is impossible, because that server is inaccessible from the outside world. So we might wanna do a proxy script:

$att = $_GET["a"]; $article = $_GET["art"]; $h = curl_init("http://".COUCHDB_SERVER."/".COUCHDB_DATABASE."/$article/$att"); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET"); $response = curl_exec($h); $contentType = curl_getinfo($h, CURLINFO_CONTENT_TYPE); header("Content-type: $contentType"); echo $response;

That way we can use our image like this: <img src=attachment.php?doc=document1&attachment=image1.jpg >