1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 * This file contains the utility functions used by Routing manager and RI
26 #ifndef ROUTING_UTILITY_H_
27 #define ROUTING_UTILITY_H_
29 //TODO Endpoint will also include this file, remove unnecessary includes.
33 #ifdef ROUTING_GATEWAY
34 #include "routingmanager.h"
43 * Maximum source or destination address length added to Route Option.
45 #define MAX_ADDR_LEN 40
50 #define GATEWAY_ID_LENGTH sizeof(uint32_t)
55 #define ENDPOINT_ID_LENGTH sizeof(uint16_t)
58 * Routing option number.
60 // TODO: We need to define proper Option number.
61 #define RM_OPTION_MESSAGE_SWITCHING 65524
64 * Macro to verify the validity of input argument with the return.
66 #define RM_NULL_CHECK_WITH_RET(arg, log_tag, log_message) \
68 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
69 return OC_STACK_INVALID_PARAM; \
73 * Macro to verify the validity of input argument.
75 #define RM_NULL_CHECK_VOID(arg, log_tag, log_message) \
77 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
82 * Macro to verify the return of an API.
84 #define RM_VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
85 {OIC_LOG_V(ERROR, TAG, "%s failed!!", #op); goto exit;} }
88 * Message types in RouteOption to differentiate a normal response and Empty response.
92 NOR = 0, /**< Normal Message. */
93 ACK, /**< Empty Acknowledgement message. */
94 RST /**< Empty Reset message. */
98 * This structure is used to hold the source address, destination address, message type and
99 * sequence number. This collectively forms the value of Route option in the message.
103 uint32_t srcGw; /**< Source gateway for this packet. */
104 uint32_t destGw; /**< Destination gateway for this packet. */
105 uint16_t mSeqNum; /**< Multicast sequence Number. */
106 uint16_t srcEp; /**< Source endpoint for this packet. */
107 uint16_t destEp; /**< Destination endpoint for this packet. */
108 uint8_t msgType; /**< Type of Message: Empty or normal. */
112 * To set the stack mode in Routing manager.
114 void RMSetStackMode(OCMode mode);
117 * Adds the destination address to the Route options.
118 * If Route option is already present, it adds the destination address information to
119 * Route option else creates a new Route option with the destination address info.
120 * @param[in] endpoint Destination address.
121 * @param[in,out] message Request/response message to add the route option
122 * @param[in] isRequest True if message is request else false.
123 * @param[out] doPost True if a POST message be sent for empty packet to
125 * @return ::CA_STATUS_OK or Appropriate error code.
127 OCStackResult RMAddInfo(const char *destination, void *message, bool isRequest,
131 * Removes the Route Option from the header options.
132 * @param[in,out] options Header options present in request/response message.
133 * @param[in,out] numOptions Number of options present in request/response message.
134 * @param[in,out] endpoint Remote address updated with the actual source of request/response.
135 * @return ::CA_STATUS_OK or Appropriate error code.
137 OCStackResult RMUpdateInfo(CAHeaderOption_t **options, uint8_t *numOptions,
138 CAEndpoint_t *endpoint);
141 * Gets the index of the routing option if present.
142 * @param[in] options Header options present in request/response message.
143 * @param[in] numOptions Number of options present in request/response message.
144 * @param[out] index Index of the route option present in Header options.
147 void RMGetRouteOptionIndex(const CAHeaderOption_t *options, uint8_t numOptions,
151 * To create a Routing option from the CARouteOption_t structure.
152 * @param[in] optValue Routing information.
153 * @param[out] options Routing information in the form of Header options.
154 * @return ::CA_STATUS_OK or Appropriate error code.
156 OCStackResult RMCreateRouteOption(const RMRouteOption_t *optValue, CAHeaderOption_t *options);
159 * To parse the routing option from the Headeroptions.
160 * @param[in] options Routing information in the form of Header options.
161 * @param[out] optValue Route information after parsing.
162 * @return ::CA_STATUS_OK or Appropriate error code.
164 OCStackResult RMParseRouteOption(const CAHeaderOption_t *options, RMRouteOption_t *optValue);
170 #endif /* ROUTING_MANAGER_H_ */