1 /* 2 * Copyright 2015, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef APF_INTERPRETER_H_ 18 #define APF_INTERPRETER_H_ 19 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * Version of APF instruction set processed by accept_packet(). 28 * Should be returned by wifi_get_packet_filter_info. 29 */ 30 #define APF_VERSION 4 31 32 /** 33 * Runs a packet filtering program over a packet. 34 * 35 * The text section containing the program instructions starts at address 36 * program and stops at + program_len - 1, and the writable data section 37 * begins at program + program_len and ends at program + ram_len - 1, 38 * as described in the following diagram: 39 * 40 * program program + program_len program + ram_len 41 * | text section | data section | 42 * +--------------------+------------------------+ 43 * 44 * @param program the program bytecode, followed by the writable data region. 45 * @param program_len the length in bytes of the read-only portion of the APF 46 * buffer pointed to by {@code program}. 47 * @param ram_len total length of the APF buffer pointed to by {@code program}, 48 * including the read-only bytecode portion and the read-write 49 * data portion. 50 * @param packet the packet bytes, starting from the 802.3 header and not 51 * including any CRC bytes at the end. 52 * @param packet_len the length of {@code packet} in bytes. 53 * @param filter_age the number of seconds since the filter was programmed. 54 * 55 * @return non-zero if packet should be passed to AP, zero if 56 * packet should be dropped. 57 */ 58 int accept_packet(uint8_t* program, uint32_t program_len, uint32_t ram_len, 59 const uint8_t* packet, uint32_t packet_len, 60 uint32_t filter_age); 61 62 #ifdef __cplusplus 63 } 64 #endif 65 66 #endif // APF_INTERPRETER_H_ 67