Holger Hans Peter Freyther | 06e8772 | 2010-05-28 02:39:52 +0800 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | demonstrate a unblock bug on the GB Proxy.. |
| 5 | """ |
| 6 | |
| 7 | bts_ns_reset = "\x02\x00\x81\x01\x01\x82\x1f\xe7\x04\x82\x1f\xe7" |
| 8 | ns_reset_ack = "\x03\x01\x82\x1f\xe7\x04\x82\x1f\xe7" |
| 9 | |
| 10 | bts_ns_unblock = "\x06" |
| 11 | ns_unblock_ack = "\x07" |
| 12 | |
| 13 | bts_bvc_reset_0 = "\x00\x00\x00\x00\x22\x04\x82\x00\x00\x07\x81\x03\x3b\x81\x02" |
| 14 | ns_bvc_reset_0_ack = "\x00\x00\x00\x00\x23\x04\x82\x00\x00" |
| 15 | |
| 16 | bts_bvc_reset_8167 = "\x00\x00\x00\x00\x22\x04\x82\x1f\xe7\x07\x81\x08\x08\x88\x72\xf4\x80\x10\x1c\x00\x9c\x40" |
| 17 | |
| 18 | |
| 19 | import socket |
| 20 | socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 21 | socket.bind(("0.0.0.0", 0)) |
| 22 | socket.setblocking(1) |
| 23 | |
| 24 | def send_and_receive(packet, port): |
| 25 | socket.sendto(packet, ("127.0.0.1", port)) |
| 26 | |
| 27 | try: |
| 28 | data, addr = socket.recvfrom(4096) |
| 29 | except socket.error, e: |
| 30 | print "ERROR", e |
| 31 | import sys |
| 32 | sys.exit(0) |
| 33 | return data |
| 34 | |
| 35 | #send stuff once |
| 36 | import sys |
| 37 | port = int(sys.argv[1]) |
| 38 | print "Sending data to port: %d" % port |
| 39 | |
| 40 | |
| 41 | res = send_and_receive(bts_ns_reset, port) |
| 42 | if res != ns_reset_ack: |
| 43 | print "Failed to get the reset ack" |
| 44 | sys.exit(-1) |
| 45 | |
| 46 | res = send_and_receive(bts_ns_unblock, port) |
| 47 | if res != ns_unblock_ack: |
| 48 | print "Failed to get the unblock ack" |
| 49 | sys.exit(-1) |
| 50 | |
| 51 | res = send_and_receive(bts_bvc_reset_0, port) |
| 52 | if res != ns_bvc_reset_0_ack: |
| 53 | print "Failed to get NS BVCI=0 reset ack" |
| 54 | sys.exit(-1) |
| 55 | |
| 56 | import time |
| 57 | time.sleep(3) |
| 58 | res = send_and_receive(bts_bvc_reset_8167, port) |
| 59 | print "Send all messages... check wireshark for the last response" |