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 OC_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 OC_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 {OC_LOG_V(ERROR, TAG, "%s failed!!", #op); goto exit;} }
88 * This structure is used to hold the hopcount, source and destination address.
92 uint32_t srcGw; /**< Source gateway for this packet. */
93 uint32_t destGw; /**< Destination gateway for this packet. */
94 uint16_t mSeqNum; /**< HopCount. */
95 uint16_t srcEp; /**< Source endpoint for this packet. */
96 uint16_t destEp; /**< Destination endpoint for this packet. */
100 * Adds the destination address to the Route options.
101 * If Route option is already present, it adds the destination address information to
102 * Route option else creates a new Route option with the destination address info.
103 * @param[in] endpoint Destination address.
104 * @param[in,out] options Header options present in the Request/response message.
105 * @param[in,out] numOptions Number of options present in the message.
106 * @return ::CA_STATUS_OK or Appropriate error code.
108 OCStackResult RMAddInfo(const char *destination, CAHeaderOption_t **options,
109 uint8_t *numOptions);
112 * Removes the Route Option from the header options.
113 * @param[in,out] options Header options present in request/response message.
114 * @param[in,out] numOptions Number of options present in request/response message.
115 * @param[in,out] endpoint Remote address updated with the actual source of request/response.
116 * @return ::CA_STATUS_OK or Appropriate error code.
118 OCStackResult RMUpdateInfo(CAHeaderOption_t **options, uint8_t *numOptions,
119 CAEndpoint_t *endpoint);
122 * Gets the index of the routing option if present.
123 * @param[in] options Header options present in request/response message.
124 * @param[in] numOptions Number of options present in request/response message.
125 * @param[out] index Index of the route option present in Header options.
128 void RMGetRouteOptionIndex(const CAHeaderOption_t *options, uint8_t numOptions,
132 * To create a Routing option from the CARouteOption_t structure.
133 * @param[in] optValue Routing information.
134 * @param[out] options Routing information in the form of Header options.
135 * @return ::CA_STATUS_OK or Appropriate error code.
137 OCStackResult RMCreateRouteOption(const RMRouteOption_t *optValue, CAHeaderOption_t *options);
140 * To parse the routing option from the Headeroptions.
141 * @param[in] options Routing information in the form of Header options.
142 * @param[out] optValue Route information after parsing.
143 * @return ::CA_STATUS_OK or Appropriate error code.
145 OCStackResult RMParseRouteOption(const CAHeaderOption_t *options, RMRouteOption_t *optValue);
151 #endif /* ROUTING_MANAGER_H_ */