1/********************************************************************* 2 PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved. 3 See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. 4 5 *********************************************************************/ 6#ifndef INCLUDE_PICO_MOCK 7#define INCLUDE_PICO_MOCK 8#include "pico_config.h" 9#include "pico_device.h" 10 11 12struct mock_frame { 13 uint8_t*buffer; 14 int len; 15 int read; 16 17 struct mock_frame*next; 18}; 19 20struct mock_device { 21 struct pico_device*dev; 22 struct mock_frame*in_head; 23 struct mock_frame*in_tail; 24 struct mock_frame*out_head; 25 struct mock_frame*out_tail; 26 27 uint8_t*mac; 28 29}; 30 31struct mock_device; 32/* A mockup-device for the purpose of testing. It provides a couple of extra "network"-functions, which represent the network-side of the device. A network_send will result in mock_poll reading something, a network_read will see if the stack has sent anything through our mock-device. */ 33void pico_mock_destroy(struct pico_device *dev); 34struct mock_device *pico_mock_create(uint8_t*mac); 35 36int pico_mock_network_read(struct mock_device*mock, void *buf, int len); 37int pico_mock_network_write(struct mock_device*mock, const void *buf, int len); 38 39/* TODO */ 40/* we could use a few checking functions, e.g. one to see if it's a valid IP packet, if it's TCP, if the IP-address matches,... */ 41/* That would be useful to avoid having to manually create buffers of what you expect, probably with masks for things that are random,... */ 42uint32_t mock_get_sender_ip4(struct mock_device*mock, void*buf, int len); 43 44int mock_ip_protocol(struct mock_device*mock, void*buf, int len); 45int mock_icmp_type(struct mock_device*mock, void*buf, int len); 46int mock_icmp_code(struct mock_device*mock, void*buf, int len); 47#endif 48