Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | :: # Copyright 2013, Big Switch Networks, Inc. |
| 2 | :: # |
| 3 | :: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | :: # the following special exception: |
| 5 | :: # |
| 6 | :: # LOXI Exception |
| 7 | :: # |
| 8 | :: # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | :: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | :: # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | :: # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | :: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | :: # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | :: # |
| 15 | :: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | :: # |
| 17 | :: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | :: # a copy of the EPL at: |
| 19 | :: # |
| 20 | :: # http://www.eclipse.org/legal/epl-v10.html |
| 21 | :: # |
| 22 | :: # Unless required by applicable law or agreed to in writing, software |
| 23 | :: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | :: # EPL for the specific language governing permissions and limitations |
| 26 | :: # under the EPL. |
| 27 | :: |
Rich Lane | d983aa5 | 2013-06-13 11:48:37 -0700 | [diff] [blame] | 28 | :: include('_copyright.c') |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 29 | |
| 30 | /**************************************************************** |
| 31 | * |
| 32 | * Low level buffer manipulation functions |
| 33 | * Requires low level type defs |
| 34 | * |
| 35 | ****************************************************************/ |
| 36 | |
| 37 | #ifndef _OF_BUFFER_H_ |
| 38 | #define _OF_BUFFER_H_ |
| 39 | |
| 40 | #include <loci/loci_base.h> |
| 41 | #include <stdio.h> |
| 42 | |
| 43 | /* Function type used for a "free" operation of a low level buffer */ |
| 44 | typedef void (*of_buffer_free_f)(void *buf); |
| 45 | |
| 46 | |
| 47 | /**************************************************************** |
| 48 | * |
| 49 | * Low level buffers accessors handling endian and alignment |
| 50 | * |
| 51 | ****************************************************************/ |
| 52 | |
| 53 | static inline void |
| 54 | buf_ipv6_get(uint8_t *buf, of_ipv6_t *val) { |
| 55 | MEMCPY(val, buf, sizeof(*val)); |
| 56 | IPV6_NTOH(val, val); /* probably a no-op */ |
| 57 | } |
| 58 | |
| 59 | static inline void |
| 60 | buf_mac_get(uint8_t *buf, of_mac_addr_t *val) { |
| 61 | MEMCPY(val, buf, sizeof(*val)); |
| 62 | } |
| 63 | |
| 64 | static inline void |
| 65 | buf_u64_get(uint8_t *buf, uint64_t *val) { |
| 66 | MEMCPY(val, buf, sizeof(*val)); |
| 67 | *val = U64_NTOH(*val); |
| 68 | } |
| 69 | |
| 70 | static inline void |
| 71 | buf_u32_get(uint8_t *buf, uint32_t *val) { |
| 72 | MEMCPY(val, buf, sizeof(*val)); |
| 73 | *val = U32_NTOH(*val); |
| 74 | } |
| 75 | |
| 76 | static inline void |
| 77 | buf_u16_get(uint8_t *buf, uint16_t *val) { |
| 78 | MEMCPY(val, buf, sizeof(uint16_t)); |
| 79 | *val = U16_NTOH(*val); |
| 80 | } |
| 81 | |
| 82 | static inline void |
| 83 | buf_u8_get(uint8_t *buf, uint8_t *val) { |
| 84 | *val = *buf; |
| 85 | } |
| 86 | |
| 87 | static inline void |
| 88 | buf_octets_get(uint8_t *buf, uint8_t *dst, int bytes) { |
| 89 | MEMCPY(dst, buf, bytes); |
| 90 | } |
| 91 | |
| 92 | static inline void |
| 93 | buf_ipv6_set(uint8_t *buf, of_ipv6_t *val) { |
| 94 | /* FIXME: If this is not a NO-OP, need to change the code */ |
| 95 | #if 1 |
| 96 | MEMCPY(buf, val, sizeof(*val)); |
| 97 | #else |
| 98 | of_ipv6_t w_val; |
| 99 | MEMCPY(&w_val, val sizeof(w_val)); |
| 100 | IPV6_HTON(w_val, w_val); |
| 101 | MEMCPY(buf, &w_val, sizeof(w_val)); |
| 102 | #endif |
| 103 | } |
| 104 | |
| 105 | static inline void |
| 106 | buf_mac_addr_set(uint8_t *buf, of_mac_addr_t *val) { |
| 107 | MEMCPY(buf, val, sizeof(of_mac_addr_t)); |
| 108 | } |
| 109 | |
| 110 | static inline void |
| 111 | buf_u64_set(uint8_t *buf, uint64_t val) { |
| 112 | val = U64_HTON(val); |
| 113 | MEMCPY(buf, &val, sizeof(uint64_t)); |
| 114 | } |
| 115 | |
| 116 | static inline void |
| 117 | buf_u32_set(uint8_t *buf, uint32_t val) { |
| 118 | val = U32_HTON(val); |
| 119 | MEMCPY(buf, &val, sizeof(uint32_t)); |
| 120 | } |
| 121 | |
| 122 | static inline void |
| 123 | buf_u16_set(uint8_t *buf, uint16_t val) { |
| 124 | val = U16_NTOH(val); |
| 125 | MEMCPY(buf, &val, sizeof(uint16_t)); |
| 126 | } |
| 127 | |
| 128 | static inline void |
| 129 | buf_u8_set(uint8_t *buf, uint8_t val) { |
| 130 | *buf = val; |
| 131 | } |
| 132 | |
| 133 | static inline void |
| 134 | buf_octets_set(uint8_t *buf, uint8_t *src, int bytes) { |
| 135 | MEMCPY(buf, src, bytes); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | #endif /* _OF_BUFFER_H_ */ |