diff options
Diffstat (limited to 'pbx')
-rw-r--r-- | pbx/main.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/pbx/main.go b/pbx/main.go new file mode 100644 index 0000000..fac444e --- /dev/null +++ b/pbx/main.go @@ -0,0 +1,80 @@ +package main + +import ( + "flag" + "log" + + "dim13.org/asn1/acse" + "dim13.org/asn1/csta" + "dim13.org/asn1/rose" + "dim13.org/asn1/spdu" + + "github.com/dim13/asn1" +) + +var pbx = flag.String("pbx", "192.168.240.20:33333", "PBX CTI Service") + +const ( + AARQ = 0x60 + AARE = 0x61 + RLRQ = 0x62 + RLRE = 0x63 + ABRT = 0x64 + Invoke = 0xa1 + Result = 0xa2 +) + +func main() { + conn, err := spdu.Dial(*pbx) + if err != nil { + log.Fatal(err) + } + defer conn.Close() + + aare, _ := acse.Associate() + conn.Write(aare) + + var connected bool + for { + buf, err := spdu.ReadAll(conn) + if err != nil { + log.Fatal(err) + } + switch buf[0] { + case AARQ: + case AARE: + result, _ := acse.AssociateResult(buf) + connected = result == acse.AssociateResultAccepted + case RLRQ: + case RLRE: + case ABRT: + connected = false + case Invoke: + id, opcode, payload, err := rose.Unmarshal(buf) + if err != nil { + log.Fatal(err) + } + switch opcode { + case csta.SystemStatusOpcode: + ss := &csta.SystemStatusArg{} + _, err := asn1.Unmarshal(payload, ss) + if err != nil { + log.Fatal(err) + } + log.Println(id, "System Status", csta.SystemStatus(ss.SystemStatus)) + null, _ := asn1.Marshal(asn1.Null{}) + res, err := rose.Marshal(id, opcode, null) + if err != nil { + log.Fatal(err) + } + conn.Write(res) + default: + log.Println("Opcode", opcode, payload) + } + case Result: + } + if !connected { + log.Fatal("EOT") + } + } +} |