1/* 2 * Test harness for encoding and decoding 802.11u GAS packets. 3 * 4 * Copyright (C) 2015, Broadcom Corporation 5 * All Rights Reserved. 6 * 7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation; 8 * the contents of this file may not be disclosed to third parties, copied 9 * or duplicated in any form, in whole or in part, without the prior 10 * written permission of Broadcom Corporation. 11 * 12 * $Id:$ 13 */ 14 15#include <stdio.h> 16#include <stdlib.h> 17#include <string.h> 18#include "proto/802.11.h" 19#include "test.h" 20#include "trace.h" 21#include "bcm_encode_gas.h" 22#include "bcm_decode_gas.h" 23 24TEST_DECLARE(); 25 26#define BUFFER_SIZE 256 27static uint8 buffer[BUFFER_SIZE]; 28static bcm_encode_t enc; 29 30/* --------------------------------------------------------------- */ 31 32static void testPktGasRequest(void) 33{ 34 bcm_decode_t dec; 35 uint8 apie[4] = {108, 2, 0, 0}; 36 uint8 req[128]; 37 int i; 38 bcm_decode_gas_t gasDecode; 39 40 for (i = 0; i < 128; i++) 41 req[i] = i; 42 43 TEST(bcm_encode_init(&enc, BUFFER_SIZE, buffer), "bcm_encode_init failed"); 44 45 TEST(bcm_encode_gas_request(&enc, 0x11, 4, apie, 128, req), 46 "bcm_encode_gas_request failed"); 47 48 TEST(bcm_decode_init(&dec, bcm_encode_length(&enc), 49 bcm_encode_buf(&enc)), "bcm_decode_init failed"); 50 51 TEST(bcm_decode_gas(&dec, &gasDecode), "bcm_decode_gas failed"); 52 TEST(gasDecode.category == DOT11_ACTION_CAT_PUBLIC, "decode failed"); 53 TEST(gasDecode.action == GAS_REQUEST_ACTION_FRAME, "decode failed"); 54 TEST(gasDecode.dialogToken == 0x11, "decode failed"); 55 TEST(gasDecode.request.apie.protocolId == 0, "decode failed"); 56 TEST(gasDecode.request.reqLen == 128, "decode failed"); 57} 58 59static void testPktGasResponse(void) 60{ 61 bcm_decode_t dec; 62 uint8 apie[4] = {108, 2, 0, 0}; 63 uint8 rsp[128]; 64 int i; 65 bcm_decode_gas_t gasDecode; 66 67 for (i = 0; i < 128; i++) 68 rsp[i] = i; 69 70 TEST(bcm_encode_init(&enc, BUFFER_SIZE, buffer), "bcm_encode_init failed"); 71 72 TEST(bcm_encode_gas_response(&enc, 0x11, 0x1234, 0x5678, 4, apie, 128, rsp), 73 "bcm_encode_gas_response failed"); 74 75 TEST(bcm_decode_init(&dec, bcm_encode_length(&enc), 76 bcm_encode_buf(&enc)), "bcm_decode_init failed"); 77 78 TEST(bcm_decode_gas(&dec, &gasDecode), "bcm_decode_gas failed"); 79 TEST(gasDecode.category == DOT11_ACTION_CAT_PUBLIC, "decode failed"); 80 TEST(gasDecode.action == GAS_RESPONSE_ACTION_FRAME, "decode failed"); 81 TEST(gasDecode.dialogToken == 0x11, "decode failed"); 82 TEST(gasDecode.response.statusCode == 0x1234, "decode failed"); 83 TEST(gasDecode.response.comebackDelay == 0x5678, "decode failed"); 84 TEST(gasDecode.response.apie.protocolId == 0, "decode failed"); 85 TEST(gasDecode.response.rspLen == 128, "decode failed"); 86} 87 88static void testPktGasComebackRequest(void) 89{ 90 bcm_decode_t dec; 91 bcm_decode_gas_t gasDecode; 92 93 TEST(bcm_encode_init(&enc, BUFFER_SIZE, buffer), "bcm_encode_init failed"); 94 95 TEST(bcm_encode_gas_comeback_request(&enc, 0x11), 96 "bcm_encode_gas_comeback_request failed"); 97 98 TEST(bcm_decode_init(&dec, bcm_encode_length(&enc), 99 bcm_encode_buf(&enc)), "bcm_decode_init failed"); 100 101 TEST(bcm_decode_gas(&dec, &gasDecode), "bcm_decode_gas failed"); 102 TEST(gasDecode.category == DOT11_ACTION_CAT_PUBLIC, "decode failed"); 103 TEST(gasDecode.action == GAS_COMEBACK_REQUEST_ACTION_FRAME, "decode failed"); 104 TEST(gasDecode.dialogToken == 0x11, "decode failed"); 105} 106 107static void testPktGasComebackResponse(void) 108{ 109 bcm_decode_t dec; 110 uint8 apie[4] = {108, 2, 0, 0}; 111 uint8 rsp[128]; 112 int i; 113 bcm_decode_gas_t gasDecode; 114 115 for (i = 0; i < 128; i++) 116 rsp[i] = i; 117 118 TEST(bcm_encode_init(&enc, BUFFER_SIZE, buffer), "bcm_encode_init failed"); 119 120 TEST(bcm_encode_gas_comeback_response(&enc, 0x11, 0x1234, 0xaa, 0x5678, 4, apie, 128, rsp), 121 "bcm_encode_gas_comeback_response failed"); 122 123 TEST(bcm_decode_init(&dec, bcm_encode_length(&enc), 124 bcm_encode_buf(&enc)), "bcm_decode_init failed"); 125 126 TEST(bcm_decode_gas(&dec, &gasDecode), "bcm_decode_gas failed"); 127 TEST(gasDecode.category == DOT11_ACTION_CAT_PUBLIC, "decode failed"); 128 TEST(gasDecode.action == GAS_COMEBACK_RESPONSE_ACTION_FRAME, "decode failed"); 129 TEST(gasDecode.dialogToken == 0x11, "decode failed"); 130 TEST(gasDecode.comebackResponse.statusCode == 0x1234, "decode failed"); 131 TEST(gasDecode.comebackResponse.fragmentId == 0xaa, "decode failed"); 132 TEST(gasDecode.comebackResponse.comebackDelay == 0x5678, "decode failed"); 133 TEST(gasDecode.comebackResponse.apie.protocolId == 0, "decode failed"); 134 TEST(gasDecode.comebackResponse.rspLen == 128, "decode failed"); 135} 136 137int main(int argc, char **argv) 138{ 139 (void) argc; 140 (void) argv; 141 142 TRACE_LEVEL_SET(TRACE_ALL); 143 TEST_INITIALIZE(); 144 145 testPktGasRequest(); 146 testPktGasResponse(); 147 testPktGasComebackRequest(); 148 testPktGasComebackResponse(); 149 150 TEST_FINALIZE(); 151 return 0; 152} 153