Packages sent and received by the fakewap program This file documents the packages sent and received by the fakewap program. Fakewap tests a WAP gateway by sending UDP packages to make simple requests for WML pages. It is meant for stress testing the gateway. The basic session looks like this (WTP is the transaction and WSP is the session protocol layer): A) Fakewap -> Gateway WTP: Invoke PDU WSP: Connect PDU B) Gateway -> Fakewap WTP: Result PDU WSP: ConnectReply PDU C) Fakewap -> Gateway WTP: Ack PDU D) Fakewap -> Gateway WTP: Invoke PDU WSP: Get PDU E) Gateway -> Fakewap WTP: Result PDU WSP: Reply PDU F) Fakewap -> Gateway WTP: Ack PDU G) Fakewap -> Gateway WTP: Invoke PDU WSP: Disconnect PDU Packets A-C open a WAP session. Packets D-F fetch a WML page. Packet G closes the session. The fakewap program does not need to understand the WAP protocols as such, it just needs to generate packets in the right order with a little variation, and keep track of which packets have received and which have not received responses. The detailed formats of the packets are listed below. Note that bits are numbered in the WAP specification with the most significant bit being 0, not 7. Unspecified bits are filled in fakewap or the gateway. Packet A) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 0 | | | | | | | | \ TID, fakewap ------------+---+---+---+---+---+---+---+---| |-- generates octet 3 | | | | | | | | | / linearly ------------+---+---+---+---+---+---+---+---| octet 4 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ------------+---+---+---+---+---+---+---+---| octet 6 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 7 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| Fakewap generates a new TID (transaction ID) for each A) packet is generates. TIDs are generated linearly. If a 15 bit counter overflows, fakewap can, for now, stop sending anything. Packet B) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 1 | | | | | | | | \ TID, gateway ------------+---+---+---+---+---+---+---+---| | copies from octet 3 | | | | | | | | | / A) packet ------------+---+---+---+---+---+---+---+---| octet 4 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 5 | | | | | | | | | \ ------------+---+---+---+---+---+---+---+---| | Session ID, ... | | | | | | | | | | generated by ------------+---+---+---+---+---+---+---+---| | gateway octet n | | | | | | | | | / ------------+---+---+---+---+---+---+---+---| octet n+1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet n+2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| Fakewap needs to extract the TID and match it to the list of A) packets it has sent that have not yet received a B) packet in response. It also needs to extract and store the Session ID because that is needed by G). The Session ID is encoded in the uintvar format specified by the WSP specification, section 8.1.2 in the WAP 1.1 version. Code for decoding it is in gw/wsp.c (should be moved elsewhere). Packet C) and F) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 0 | | | | | | | | \ TID, must be ------------+---+---+---+---+---+---+---+---| | same as in octet 3 | | | | | | | | | / A) or D) packet. ------------+---+---+---+---+---+---+---+---| Packets C) and F) are identical, except C) gets its TID from an A) packet, and F) from a D) packet. Packet D) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 0 | | | | | | | | \ TID, fakewap ------------+---+---+---+---+---+---+---+---| | generates a octet 3 | | | | | | | | | / new one ------------+---+---+---+---+---+---+---+---| octet 4 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 5 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 6 | | | | | | | | | \ ------------+---+---+---+---+---+---+---+---| | ... | | | | | | | | | | URI length ------------+---+---+---+---+---+---+---+---| | octet n | | | | | | | | | / ------------+---+---+---+---+---+---+---+---| octet n+1 | | | | | | | | | \ ------------+---+---+---+---+---+---+---+---| | ... | | | | | | | | | | URI ------------+---+---+---+---+---+---+---+---| | octet n+m | | | | | | | | | / ------------+---+---+---+---+---+---+---+---| The URI (or URL) length is specified with uintvar (code to generate them also in gw/wsp.c). The URL itself is just the octets of the string copied as is. Packet E) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 1 | | | | | | | | \ TID, gateway ------------+---+---+---+---+---+---+---+---| | copies from octet 3 | | | | | | | | | / D) packet ------------+---+---+---+---+---+---+---+---| octet 4 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 5 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ------------+---+---+---+---+---+---+---+---| octet 7 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 8 | | | | | | | | | \ ------------+---+---+---+---+---+---+---+---| | Compiled WML ... | | | | | | | | | | page. ------------+---+---+---+---+---+---+---+---| | octet n | | | | | | | | | / ------------+---+---+---+---+---+---+---+---| Fakewap needs to extract the TID so it can match it to the D) packet it sent. It can ignore the WML page for now. Packet G) bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------+---+---+---+---+---+---+---+---| octet 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | ------------+---+---+---+---+---+---+---+---| octet 2 | 0 | | | | | | | | \ TID, fakewap ------------+---+---+---+---+---+---+---+---| | generates a octet 3 | | | | | | | | | / new one ------------+---+---+---+---+---+---+---+---| octet 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------+---+---+---+---+---+---+---+---| octet 5 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | ------------+---+---+---+---+---+---+---+---| octet 6 | | | | | | | | | \ ------------+---+---+---+---+---+---+---+---| | Session ID, ... | | | | | | | | | | copied from ------------+---+---+---+---+---+---+---+---| | B) packet. octet n | | | | | | | | | / ------------+---+---+---+---+---+---+---+---|