1 /*
2 * Copyright 2023, 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 #include <string.h>
18
19 #include "apf_interpreter.h"
20 #include "test_buf_allocator.h"
21
22 uint8_t apf_test_buffer[sizeof(apf_test_buffer)];
23 uint32_t apf_test_tx_packet_len;
24 uint8_t apf_test_tx_dscp;
25
26 /**
27 * Test implementation of apf_allocate_buffer()
28 *
29 * Clean up the apf_test_buffer and return the pointer to beginning of the buffer region.
30 */
apf_allocate_buffer(void * ctx,uint32_t size)31 uint8_t* apf_allocate_buffer(__attribute__ ((unused)) void* ctx, uint32_t size) {
32 if (size > sizeof(apf_test_buffer)) {
33 return NULL;
34 }
35 return apf_test_buffer;
36 }
37
38 /**
39 * Test implementation of apf_transmit_buffer()
40 *
41 * Copy the content of allocated buffer to the apf_test_tx_packet region.
42 */
apf_transmit_buffer(void * ctx,uint8_t * ptr,uint32_t len,uint8_t dscp)43 int apf_transmit_buffer(__attribute__((unused)) void* ctx, uint8_t* ptr,
44 uint32_t len, uint8_t dscp) {
45 if (len && len < ETH_HLEN) return -1;
46 if (ptr != apf_test_buffer) return -1;
47 apf_test_tx_packet_len = len;
48 apf_test_tx_dscp = dscp;
49 return 0;
50 }
51