Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 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 | |
| 18 | #ifndef VAPI_INTERNAL_H |
| 19 | #define VAPI_INTERNAL_H |
| 20 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 21 | #include <endian.h> |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 22 | #include <string.h> |
| 23 | #include <vppinfra/types.h> |
| 24 | |
| 25 | /** |
| 26 | * @file vapi_internal.h |
| 27 | * |
| 28 | * internal vpp api C declarations |
| 29 | * |
| 30 | * This file contains internal vpp api C declarations. It's not intended to be |
| 31 | * used by the client programmer and the API defined here might change at any |
| 32 | * time.. |
| 33 | */ |
| 34 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 39 | struct vapi_ctx_s; |
| 40 | |
| 41 | typedef struct __attribute__ ((__packed__)) |
| 42 | { |
| 43 | u16 _vl_msg_id; |
| 44 | u32 context; |
| 45 | } vapi_type_msg_header1_t; |
| 46 | |
| 47 | typedef struct __attribute__ ((__packed__)) |
| 48 | { |
| 49 | u16 _vl_msg_id; |
| 50 | u32 client_index; |
| 51 | u32 context; |
| 52 | } vapi_type_msg_header2_t; |
| 53 | |
| 54 | static inline void |
| 55 | vapi_type_msg_header1_t_hton (vapi_type_msg_header1_t * h) |
| 56 | { |
| 57 | h->_vl_msg_id = htobe16 (h->_vl_msg_id); |
| 58 | } |
| 59 | |
| 60 | static inline void |
| 61 | vapi_type_msg_header1_t_ntoh (vapi_type_msg_header1_t * h) |
| 62 | { |
| 63 | h->_vl_msg_id = be16toh (h->_vl_msg_id); |
| 64 | } |
| 65 | |
| 66 | static inline void |
| 67 | vapi_type_msg_header2_t_hton (vapi_type_msg_header2_t * h) |
| 68 | { |
| 69 | h->_vl_msg_id = htobe16 (h->_vl_msg_id); |
| 70 | } |
| 71 | |
| 72 | static inline void |
| 73 | vapi_type_msg_header2_t_ntoh (vapi_type_msg_header2_t * h) |
| 74 | { |
| 75 | h->_vl_msg_id = be16toh (h->_vl_msg_id); |
| 76 | } |
| 77 | |
| 78 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 79 | #include <vapi/vapi.h> |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 80 | |
| 81 | typedef vapi_error_e (*vapi_cb_t) (struct vapi_ctx_s *, void *, vapi_error_e, |
| 82 | bool, void *); |
| 83 | |
| 84 | typedef void (*generic_swap_fn_t) (void *payload); |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 85 | typedef int (*verify_msg_size_fn_t) (void *msg, uword buf_size); |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 86 | |
| 87 | typedef struct |
| 88 | { |
| 89 | const char *name; |
| 90 | size_t name_len; |
| 91 | const char *name_with_crc; |
| 92 | size_t name_with_crc_len; |
| 93 | bool has_context; |
Neale Ranns | fd67ece | 2017-11-02 11:59:14 -0700 | [diff] [blame] | 94 | unsigned int context_offset; |
| 95 | unsigned int payload_offset; |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 96 | verify_msg_size_fn_t verify_msg_size; |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 97 | generic_swap_fn_t swap_to_be; |
| 98 | generic_swap_fn_t swap_to_host; |
| 99 | vapi_msg_id_t id; /* assigned at run-time */ |
| 100 | } vapi_message_desc_t; |
| 101 | |
| 102 | typedef struct |
| 103 | { |
| 104 | const char *name; |
| 105 | int payload_offset; |
| 106 | size_t size; |
| 107 | void (*swap_to_be) (void *payload); |
| 108 | void (*swap_to_host) (void *payload); |
| 109 | } vapi_event_desc_t; |
| 110 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 111 | vapi_msg_id_t vapi_register_msg (vapi_message_desc_t * msg); |
| 112 | u16 vapi_lookup_vl_msg_id (vapi_ctx_t ctx, vapi_msg_id_t id); |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 113 | vapi_msg_id_t vapi_lookup_vapi_msg_id_t (vapi_ctx_t ctx, u16 vl_msg_id); |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 114 | int vapi_get_client_index (vapi_ctx_t ctx); |
| 115 | bool vapi_is_nonblocking (vapi_ctx_t ctx); |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 116 | bool vapi_requests_empty (vapi_ctx_t ctx); |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 117 | bool vapi_requests_full (vapi_ctx_t ctx); |
| 118 | size_t vapi_get_request_count (vapi_ctx_t ctx); |
| 119 | size_t vapi_get_max_request_count (vapi_ctx_t ctx); |
| 120 | u32 vapi_gen_req_context (vapi_ctx_t ctx); |
| 121 | void vapi_store_request (vapi_ctx_t ctx, u32 context, bool is_dump, |
| 122 | vapi_cb_t callback, void *callback_ctx); |
| 123 | int vapi_get_payload_offset (vapi_msg_id_t id); |
| 124 | void (*vapi_get_swap_to_host_func (vapi_msg_id_t id)) (void *payload); |
| 125 | void (*vapi_get_swap_to_be_func (vapi_msg_id_t id)) (void *payload); |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 126 | size_t vapi_get_context_offset (vapi_msg_id_t id); |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 127 | bool vapi_msg_is_with_context (vapi_msg_id_t id); |
| 128 | size_t vapi_get_message_count(); |
| 129 | const char *vapi_get_msg_name(vapi_msg_id_t id); |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 130 | |
| 131 | vapi_error_e vapi_producer_lock (vapi_ctx_t ctx); |
| 132 | vapi_error_e vapi_producer_unlock (vapi_ctx_t ctx); |
| 133 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
| 137 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 138 | #endif |