From aebf74f11639b3606685799d7d4074fc89df3407 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 15 Oct 2015 19:56:24 +0200 Subject: Move out of the way --- pbx/main.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 pbx/main.go (limited to 'pbx') 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") + } + } +} -- cgit v1.2.3