Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | /*
* Copyright (c) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef TP_H
#define TP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <data/json.h>
#include <net/net_pkt.h>
#include "connection.h"
#if IS_ENABLED(CONFIG_NET_TEST_PROTOCOL)
#define TP_SEQ 0
#define TP_ACK 1
#define TP_BOOL 1
#define TP_INT 2
enum tp_type { /* Test protocol message type */
TP_NONE = 0,
TP_COMMAND,
TP_CONFIG_REQUEST,
TP_CONFIG_REPLY,
TP_INTROSPECT_REQUEST,
TP_INTROSPECT_REPLY,
TP_INTROSPECT_MEMORY_REQUEST,
TP_INTROSPECT_MEMORY_REPLY,
TP_INTROSPECT_PACKETS_REQUEST,
TP_INTROSPECT_PACKETS_REPLY,
TP_DEBUG_STOP,
TP_DEBUG_STEP,
TP_DEBUG_CONTINUE,
TP_DEBUG_RESPONSE,
TP_DEBUG_BREAKPOINT_ADD,
TP_DEBUG_BREAKPOINT_DELETE,
TP_TRACE_ADD,
TP_TRACE_DELETE
};
extern bool tp_trace;
extern enum tp_type tp_state;
struct tp_msg {
const char *msg;
};
static const struct json_obj_descr tp_msg_dsc[] = {
JSON_OBJ_DESCR_PRIM(struct tp_msg, msg, JSON_TOK_STRING)
};
struct tp {
enum tp_type type;
const char *msg;
const char *status;
const char *state;
int seq;
int ack;
const char *rcv;
const char *data;
const char *op;
};
#define json_str(_type, _field) \
JSON_OBJ_DESCR_PRIM(struct _type, _field, JSON_TOK_STRING)
#define json_num(_type, _field) \
JSON_OBJ_DESCR_PRIM(struct _type, _field, JSON_TOK_NUMBER)
static const struct json_obj_descr tp_descr[] = {
json_str(tp, msg),
json_str(tp, status),
json_str(tp, state),
json_num(tp, seq),
json_num(tp, ack),
json_str(tp, rcv),
json_str(tp, data),
json_str(tp, op),
};
struct tp_entry {
const char *key;
const char *value;
};
static const struct json_obj_descr tp_entry_dsc[] = {
JSON_OBJ_DESCR_PRIM(struct tp_entry, key, JSON_TOK_STRING),
JSON_OBJ_DESCR_PRIM(struct tp_entry, value, JSON_TOK_STRING),
};
struct tp_new {
const char *msg;
struct tp_entry data[10];
size_t num_entries;
};
static const struct json_obj_descr tp_new_dsc[] = {
JSON_OBJ_DESCR_PRIM(struct tp_new, msg, JSON_TOK_STRING),
JSON_OBJ_DESCR_OBJ_ARRAY(struct tp_new, data, 10, num_entries,
tp_entry_dsc, ARRAY_SIZE(tp_entry_dsc)),
};
enum net_verdict tp_input(struct net_conn *net_conn,
struct net_pkt *pkt,
union net_ip_header *ip,
union net_proto_header *proto,
void *user_data);
char *tp_basename(char *path);
const char *tp_hex_to_str(void *data, size_t len);
size_t tp_str_to_hex(void *buf, size_t bufsize, const char *s);
void _tp_output(sa_family_t af, struct net_if *iface, void *data,
size_t data_len, const char *file, int line);
#define tp_output(_af, _iface, _data, _data_len) \
_tp_output(_af, _iface, _data, _data_len, \
tp_basename(__FILE__), __LINE__)
void tp_pkt_adj(struct net_pkt *pkt, int req_len);
enum tp_type tp_msg_to_type(const char *s);
void *tp_malloc(size_t size, const char *file, int line, const char *func);
void tp_free(void *ptr, const char *file, int line, const char *func);
void *tp_calloc(size_t nmemb, size_t size, const char *file, int line,
const char *func);
void tp_mem_stat(void);
struct net_buf *tp_nbuf_alloc(struct net_buf_pool *pool, size_t len,
const char *file, int line, const char *func);
struct net_buf *tp_nbuf_clone(struct net_buf *buf, const char *file, int line,
const char *func);
void tp_nbuf_unref(struct net_buf *nbuf, const char *file, int line,
const char *func);
void tp_nbuf_stat(void);
void tp_pkt_alloc(struct net_pkt *pkt,
const char *file, int line);
struct net_pkt *tp_pkt_clone(struct net_pkt *pkt, const char *file, int line);
void tp_pkt_unref(struct net_pkt *pkt, const char *file, int line);
void tp_pkt_stat(void);
u32_t tp_seq_track(int kind, u32_t *pvalue, int req,
const char *file, int line, const char *func);
void tp_seq_stat(void);
struct tp *json_to_tp(void *data, size_t data_len);
enum tp_type json_decode_msg(void *data, size_t data_len);
struct tp_new *json_to_tp_new(void *data, size_t data_len);
void tp_encode(struct tp *tp, void *data, size_t *data_len);
void tp_new_to_json(struct tp_new *tp, void *data, size_t *data_len);
void tp_new_find_and_apply(struct tp_new *tp, const char *key, void *value,
int type);
void tp_out(sa_family_t af, struct net_if *iface, const char *msg,
const char *key, const char *value);
bool tp_tap_input(struct net_pkt *pkt);
#else /* else of IS_ENABLED(CONFIG_NET_TEST_PROTOCOL) */
#define tp_tap_input(_pkt) false
#define tp_input(_pkt) false
#define tp_out(args...)
#endif /* end of IS_ENABLED(CONFIG_NET_TEST_PROTOCOL) */
#ifdef __cplusplus
}
#endif
#endif /* TP_H */
|