mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/source/include/m2mtlvdeserializer.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #include "mbed-client/m2mvector.h" |
mbedAustin | 11:cada08fc8a70 | 17 | #include "mbed-client/m2mobject.h" |
mbedAustin | 11:cada08fc8a70 | 18 | #include "mbed-client/m2mobjectinstance.h" |
mbedAustin | 11:cada08fc8a70 | 19 | #include "mbed-client/m2mresource.h" |
mbedAustin | 11:cada08fc8a70 | 20 | |
mbedAustin | 11:cada08fc8a70 | 21 | /** |
mbedAustin | 11:cada08fc8a70 | 22 | * @brief M2MTLVDeserializer |
mbedAustin | 11:cada08fc8a70 | 23 | * TLV Deserialiser get the object instances and resources as binary data and |
mbedAustin | 11:cada08fc8a70 | 24 | * builds the <code>lwm2m</code> representation from it. See OMA-LWM2M |
mbedAustin | 11:cada08fc8a70 | 25 | * specification, chapter 6.1 for the resource model and chapter 6.3.3 for |
mbedAustin | 11:cada08fc8a70 | 26 | * the OMA-TLV specification. |
mbedAustin | 11:cada08fc8a70 | 27 | */ |
mbedAustin | 11:cada08fc8a70 | 28 | class M2MTLVDeserializer { |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | public : |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | typedef enum { |
mbedAustin | 11:cada08fc8a70 | 33 | None, |
mbedAustin | 11:cada08fc8a70 | 34 | NotFound, |
mbedAustin | 11:cada08fc8a70 | 35 | NotAllowed, |
mbedAustin | 11:cada08fc8a70 | 36 | NotValid |
mbedAustin | 11:cada08fc8a70 | 37 | } Error; |
mbedAustin | 11:cada08fc8a70 | 38 | |
mbedAustin | 11:cada08fc8a70 | 39 | typedef enum { |
mbedAustin | 11:cada08fc8a70 | 40 | Put, |
mbedAustin | 11:cada08fc8a70 | 41 | Post |
mbedAustin | 11:cada08fc8a70 | 42 | } Operation; |
mbedAustin | 11:cada08fc8a70 | 43 | |
mbedAustin | 11:cada08fc8a70 | 44 | |
mbedAustin | 11:cada08fc8a70 | 45 | /** |
mbedAustin | 11:cada08fc8a70 | 46 | * Constructor. |
mbedAustin | 11:cada08fc8a70 | 47 | */ |
mbedAustin | 11:cada08fc8a70 | 48 | M2MTLVDeserializer(); |
mbedAustin | 11:cada08fc8a70 | 49 | |
mbedAustin | 11:cada08fc8a70 | 50 | /** |
mbedAustin | 11:cada08fc8a70 | 51 | * Destructor. |
mbedAustin | 11:cada08fc8a70 | 52 | */ |
mbedAustin | 11:cada08fc8a70 | 53 | virtual ~M2MTLVDeserializer(); |
mbedAustin | 11:cada08fc8a70 | 54 | |
mbedAustin | 11:cada08fc8a70 | 55 | /** |
mbedAustin | 11:cada08fc8a70 | 56 | * This method checks whether the given binary encodes an object instance |
mbedAustin | 11:cada08fc8a70 | 57 | * or something else. It returns <code>true</code> if bits 7-6 of the first |
mbedAustin | 11:cada08fc8a70 | 58 | * byte is "00". |
mbedAustin | 11:cada08fc8a70 | 59 | * @param tlv Binary to be checked as LWM2M object instance |
mbedAustin | 11:cada08fc8a70 | 60 | * @return <code>true</code> or <code>false</code>. |
mbedAustin | 11:cada08fc8a70 | 61 | */ |
mbedAustin | 11:cada08fc8a70 | 62 | bool is_object_instance(uint8_t *tlv); |
mbedAustin | 11:cada08fc8a70 | 63 | |
mbedAustin | 11:cada08fc8a70 | 64 | |
mbedAustin | 11:cada08fc8a70 | 65 | /** |
mbedAustin | 11:cada08fc8a70 | 66 | * This method checks whether the given binary encodes a resource or |
mbedAustin | 11:cada08fc8a70 | 67 | * something else. It returns <code>true</code> if bits 7-6 of the first |
mbedAustin | 11:cada08fc8a70 | 68 | * byte is "11". |
mbedAustin | 11:cada08fc8a70 | 69 | * @param tlv Binary to be checked as LWM2M resource. |
mbedAustin | 11:cada08fc8a70 | 70 | * @return <code>true</code> or <code>false</code>. |
mbedAustin | 11:cada08fc8a70 | 71 | */ |
mbedAustin | 11:cada08fc8a70 | 72 | bool is_resource(uint8_t *tlv); |
mbedAustin | 11:cada08fc8a70 | 73 | |
mbedAustin | 11:cada08fc8a70 | 74 | /** |
mbedAustin | 11:cada08fc8a70 | 75 | * This method checks whether the given binary encodes a multiple resource |
mbedAustin | 11:cada08fc8a70 | 76 | * or something else. It returns <code>true</code> if bits 7-6 of the first |
mbedAustin | 11:cada08fc8a70 | 77 | * byte is "10". |
mbedAustin | 11:cada08fc8a70 | 78 | * @param tlv Binary to be checked as LWM2M multiple resource. |
mbedAustin | 11:cada08fc8a70 | 79 | * @return <code>true</code> or <code>false</code>. |
mbedAustin | 11:cada08fc8a70 | 80 | */ |
mbedAustin | 11:cada08fc8a70 | 81 | bool is_multiple_resource(uint8_t *tlv); |
mbedAustin | 11:cada08fc8a70 | 82 | |
mbedAustin | 11:cada08fc8a70 | 83 | /** |
mbedAustin | 11:cada08fc8a70 | 84 | * This method checks whether the given binary encodes a resource instance |
mbedAustin | 11:cada08fc8a70 | 85 | * or something else. It returns <code>true</code> if bits 7-6 of the first |
mbedAustin | 11:cada08fc8a70 | 86 | * byte is "01". |
mbedAustin | 11:cada08fc8a70 | 87 | * @param tlv Binary to be checked as LWM2M resource instance. |
mbedAustin | 11:cada08fc8a70 | 88 | * @return <code>true</code> or <code>false</code>. |
mbedAustin | 11:cada08fc8a70 | 89 | */ |
mbedAustin | 11:cada08fc8a70 | 90 | bool is_resource_instance(uint8_t *tlv); |
mbedAustin | 11:cada08fc8a70 | 91 | |
mbedAustin | 11:cada08fc8a70 | 92 | /** |
mbedAustin | 11:cada08fc8a70 | 93 | * Deserialises the given binary that must encode object instances. Binary |
mbedAustin | 11:cada08fc8a70 | 94 | * array can be checked before invoking this method with |
mbedAustin | 11:cada08fc8a70 | 95 | */ |
mbedAustin | 11:cada08fc8a70 | 96 | M2MTLVDeserializer::Error deserialise_object_instances(uint8_t* tlv, |
mbedAustin | 11:cada08fc8a70 | 97 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 98 | M2MObject &object, |
mbedAustin | 11:cada08fc8a70 | 99 | M2MTLVDeserializer::Operation operation); |
mbedAustin | 11:cada08fc8a70 | 100 | |
mbedAustin | 11:cada08fc8a70 | 101 | /** |
mbedAustin | 11:cada08fc8a70 | 102 | * Deserialises the given binary that must encode resources. Binary array |
mbedAustin | 11:cada08fc8a70 | 103 | * can be checked before invoking this method. |
mbedAustin | 11:cada08fc8a70 | 104 | */ |
mbedAustin | 11:cada08fc8a70 | 105 | M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 106 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 107 | M2MObjectInstance &object_instance, |
mbedAustin | 11:cada08fc8a70 | 108 | M2MTLVDeserializer::Operation operation); |
mbedAustin | 11:cada08fc8a70 | 109 | |
mbedAustin | 11:cada08fc8a70 | 110 | /** |
mbedAustin | 11:cada08fc8a70 | 111 | * Deserialises the given binary that must encode resource instances. Binary array |
mbedAustin | 11:cada08fc8a70 | 112 | * can be checked before invoking this method. |
mbedAustin | 11:cada08fc8a70 | 113 | */ |
mbedAustin | 11:cada08fc8a70 | 114 | M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 115 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 116 | M2MResource &resource, |
mbedAustin | 11:cada08fc8a70 | 117 | M2MTLVDeserializer::Operation operation); |
mbedAustin | 11:cada08fc8a70 | 118 | /** |
mbedAustin | 11:cada08fc8a70 | 119 | * This method return object instance id or resource id. |
mbedAustin | 11:cada08fc8a70 | 120 | * @param tlv Binary to be checked |
mbedAustin | 11:cada08fc8a70 | 121 | * @return Object instance id or resource id. |
mbedAustin | 11:cada08fc8a70 | 122 | */ |
mbedAustin | 11:cada08fc8a70 | 123 | uint16_t instance_id(uint8_t *tlv); |
mbedAustin | 11:cada08fc8a70 | 124 | |
mbedAustin | 11:cada08fc8a70 | 125 | private: |
mbedAustin | 11:cada08fc8a70 | 126 | |
mbedAustin | 11:cada08fc8a70 | 127 | M2MTLVDeserializer::Error deserialize_object_instances(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 128 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 129 | uint32_t offset, |
mbedAustin | 11:cada08fc8a70 | 130 | M2MObject &object, |
mbedAustin | 11:cada08fc8a70 | 131 | M2MTLVDeserializer::Operation operation, |
mbedAustin | 11:cada08fc8a70 | 132 | bool update_value); |
mbedAustin | 11:cada08fc8a70 | 133 | |
mbedAustin | 11:cada08fc8a70 | 134 | M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 135 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 136 | uint32_t offset, |
mbedAustin | 11:cada08fc8a70 | 137 | M2MObjectInstance &object_instance, |
mbedAustin | 11:cada08fc8a70 | 138 | M2MTLVDeserializer::Operation operation, |
mbedAustin | 11:cada08fc8a70 | 139 | bool update_value); |
mbedAustin | 11:cada08fc8a70 | 140 | |
mbedAustin | 11:cada08fc8a70 | 141 | M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 142 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 143 | uint32_t offset, |
mbedAustin | 11:cada08fc8a70 | 144 | M2MResource &resource, |
mbedAustin | 11:cada08fc8a70 | 145 | M2MObjectInstance &object_instance, |
mbedAustin | 11:cada08fc8a70 | 146 | M2MTLVDeserializer::Operation operation, |
mbedAustin | 11:cada08fc8a70 | 147 | bool update_value); |
mbedAustin | 11:cada08fc8a70 | 148 | |
mbedAustin | 11:cada08fc8a70 | 149 | M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv, |
mbedAustin | 11:cada08fc8a70 | 150 | uint32_t tlv_size, |
mbedAustin | 11:cada08fc8a70 | 151 | uint32_t offset, |
mbedAustin | 11:cada08fc8a70 | 152 | M2MResource &resource, |
mbedAustin | 11:cada08fc8a70 | 153 | M2MTLVDeserializer::Operation operation, |
mbedAustin | 11:cada08fc8a70 | 154 | bool update_value); |
mbedAustin | 11:cada08fc8a70 | 155 | |
mbedAustin | 11:cada08fc8a70 | 156 | bool is_object_instance(uint8_t *tlv, uint32_t offset); |
mbedAustin | 11:cada08fc8a70 | 157 | |
mbedAustin | 11:cada08fc8a70 | 158 | bool is_resource(uint8_t *tlv, uint32_t offset); |
mbedAustin | 11:cada08fc8a70 | 159 | |
mbedAustin | 11:cada08fc8a70 | 160 | bool is_multiple_resource(uint8_t *tlv, uint32_t offset); |
mbedAustin | 11:cada08fc8a70 | 161 | |
mbedAustin | 11:cada08fc8a70 | 162 | bool is_resource_instance(uint8_t *tlv, uint32_t offset); |
mbedAustin | 11:cada08fc8a70 | 163 | }; |
mbedAustin | 11:cada08fc8a70 | 164 | |
mbedAustin | 11:cada08fc8a70 | 165 | class TypeIdLength { |
mbedAustin | 11:cada08fc8a70 | 166 | |
mbedAustin | 11:cada08fc8a70 | 167 | public: |
mbedAustin | 11:cada08fc8a70 | 168 | |
mbedAustin | 11:cada08fc8a70 | 169 | static TypeIdLength* createTypeIdLength(uint8_t *tlv, uint32_t offset); |
mbedAustin | 11:cada08fc8a70 | 170 | |
mbedAustin | 11:cada08fc8a70 | 171 | TypeIdLength* deserialize(); |
mbedAustin | 11:cada08fc8a70 | 172 | |
mbedAustin | 11:cada08fc8a70 | 173 | void deserialiseID (uint32_t idLength); |
mbedAustin | 11:cada08fc8a70 | 174 | |
mbedAustin | 11:cada08fc8a70 | 175 | void deserialiseLength (uint32_t lengthType); |
mbedAustin | 11:cada08fc8a70 | 176 | |
mbedAustin | 11:cada08fc8a70 | 177 | uint8_t *_tlv; |
mbedAustin | 11:cada08fc8a70 | 178 | uint32_t _offset; |
mbedAustin | 11:cada08fc8a70 | 179 | uint32_t _type; |
mbedAustin | 11:cada08fc8a70 | 180 | uint16_t _id; |
mbedAustin | 11:cada08fc8a70 | 181 | uint32_t _length; |
mbedAustin | 11:cada08fc8a70 | 182 | |
mbedAustin | 11:cada08fc8a70 | 183 | friend class Test_M2MTLVDeserializer; |
mbedAustin | 11:cada08fc8a70 | 184 | }; |