Caller-IDs arrive from the US without a 1, just the NXXNXXXXXX number. Other calls from outside the US arrive starting with a country code.
With the very kind help of Daniel we managed to get this working. Here's what we did:
1) in the trunk, add this to the PEER details (where mytrunk is the name of your trunk above in Trunk Name field:
context=from-trunk-sip-mytrunk-fixcid
2) in /etc/asterisk/extensions_custom.conf, add the following lines, again replacing mytrunk
[from-trunk-sip-mytrunk-fixcid]
exten => _X./_NXXNXXXXXX,1,NoOp(Caller ID is: ${CALLERID(num)})
exten => _X./_NXXNXXXXXX,n,Set(CALLERID(num)=001${CALLERID(num)})
exten => _X./_001NXXNXXXXXX,n,NoOp(Caller ID is now: ${CALLERID(num)})
exten => _X./_001NXXNXXXXXX,n,Goto(from-trunk-sip-mytrunk,${EXTEN},1)
exten => _X.,1,Set(CALLERID(num)=00${CALLERID(num)})
exten => _X.,n,Goto(from-trunk-sip-mytrunk,${EXTEN},1)
Explanation line by line:
1. create the new from-trunk-sip-mytrunk-fixcid context.
2. _X. matches any DID number, then a /, then _NXXNXXXXXX matches a US style number in the caller-id, (could be any valid pattern). This line merely logs the current caller id.
3. sets the new caller id and prepends 001 to US numbers
4. now here's the part I missed above, the caller-id has changed, so you must add 001 now to the caller-id match or the call falls through to voicemail or somewhere unknown! This line merely logs the caller-id after it has been edited. You can't use 'same =>' here because IT'S NO LONGER THE SAME.
5. again, matching the changed caller-id, now send the call back to the trunk. You need this line, you can't let it fall through or it falls through to voicemail or somewhere unknown.
6. this catches non-US numbers (or rather things not in the previous pattern sequence) and adds 00 to them
7, sends them back to the trunk.
Now all calls come into the phone with 00 counry-code number and they can all be redialed.
Another thing that did not help was that my Siemens phone was set to UK mode which removed the 44 in front of numbers and replaced with a 0, hence really confusing the situation because I thought I was getting just a number starting with 0 when I dialed my US trunk!
A big thank you to Daniel who spent a couple hours on the phone with me this morning. I must say I have a better understanding of dialplans now!