ua_pubsub_udp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright (c) 2017-2018 Fraunhofer IOSB (Author: Andreas Ebner)
  6. * Copyright 2018 (c) Jose Cabral, fortiss GmbH
  7. */
  8. #include <open62541/plugin/log_stdout.h>
  9. #include <open62541/plugin/pubsub_udp.h>
  10. #include <open62541/util.h>
  11. // UDP multicast network layer specific internal data
  12. typedef struct {
  13. int ai_family; //Protocol family for socket. IPv4/IPv6
  14. struct sockaddr_storage *ai_addr; //https://msdn.microsoft.com/de-de/library/windows/desktop/ms740496(v=vs.85).aspx
  15. UA_UInt32 messageTTL;
  16. UA_Boolean enableLoopback;
  17. UA_Boolean enableReuse;
  18. } UA_PubSubChannelDataUDPMC;
  19. /**
  20. * Open communication socket based on the connectionConfig. Protocol specific parameters are
  21. * provided within the connectionConfig as KeyValuePair.
  22. * Currently supported options: "ttl" , "loopback", "reuse"
  23. *
  24. * @return ref to created channel, NULL on error
  25. */
  26. static UA_PubSubChannel *
  27. UA_PubSubChannelUDPMC_open(const UA_PubSubConnectionConfig *connectionConfig) {
  28. UA_initialize_architecture_network();
  29. UA_NetworkAddressUrlDataType address;
  30. if(UA_Variant_hasScalarType(&connectionConfig->address, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE])){
  31. address = *(UA_NetworkAddressUrlDataType *)connectionConfig->address.data;
  32. } else {
  33. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Invalid Address.");
  34. return NULL;
  35. }
  36. //allocate and init memory for the UDP multicast specific internal data
  37. UA_PubSubChannelDataUDPMC * channelDataUDPMC =
  38. (UA_PubSubChannelDataUDPMC *) UA_calloc(1, (sizeof(UA_PubSubChannelDataUDPMC)));
  39. if(!channelDataUDPMC){
  40. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Out of memory.");
  41. return NULL;
  42. }
  43. //set default values
  44. UA_PubSubChannelDataUDPMC defaultValues = {0, NULL, 255, UA_TRUE, UA_TRUE};
  45. memcpy(channelDataUDPMC, &defaultValues, sizeof(UA_PubSubChannelDataUDPMC));
  46. //iterate over the given KeyValuePair paramters
  47. UA_String ttlParam = UA_STRING("ttl"), loopbackParam = UA_STRING("loopback"), reuseParam = UA_STRING("reuse");
  48. for(size_t i = 0; i < connectionConfig->connectionPropertiesSize; i++){
  49. if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &ttlParam)){
  50. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_UINT32])){
  51. channelDataUDPMC->messageTTL = *(UA_UInt32 *) connectionConfig->connectionProperties[i].value.data;
  52. }
  53. } else if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &loopbackParam)){
  54. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_BOOLEAN])){
  55. channelDataUDPMC->enableLoopback = *(UA_Boolean *) connectionConfig->connectionProperties[i].value.data;
  56. }
  57. } else if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &reuseParam)){
  58. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_BOOLEAN])){
  59. channelDataUDPMC->enableReuse = *(UA_Boolean *) connectionConfig->connectionProperties[i].value.data;
  60. }
  61. } else {
  62. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation. Unknown connection parameter.");
  63. }
  64. }
  65. UA_PubSubChannel *newChannel = (UA_PubSubChannel *) UA_calloc(1, sizeof(UA_PubSubChannel));
  66. if(!newChannel){
  67. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Out of memory.");
  68. UA_free(channelDataUDPMC);
  69. return NULL;
  70. }
  71. struct addrinfo hints, *rp, *requestResult = NULL;
  72. memset(&hints, 0, sizeof hints);
  73. hints.ai_family = AF_UNSPEC;
  74. hints.ai_socktype = SOCK_DGRAM;
  75. hints.ai_flags = 0;
  76. hints.ai_protocol = 0;
  77. UA_String hostname, path;
  78. UA_UInt16 networkPort;
  79. if(UA_parseEndpointUrl(&address.url, &hostname, &networkPort, &path) != UA_STATUSCODE_GOOD){
  80. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  81. "PubSub Connection creation failed. Invalid URL.");
  82. UA_free(channelDataUDPMC);
  83. UA_free(newChannel);
  84. return NULL;
  85. }
  86. if(hostname.length > 512) {
  87. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  88. "PubSub Connection creation failed. URL maximum length is 512.");
  89. UA_free(channelDataUDPMC);
  90. UA_free(newChannel);
  91. return NULL;
  92. }
  93. UA_STACKARRAY(char, addressAsChar, sizeof(char) * hostname.length +1);
  94. memcpy(addressAsChar, hostname.data, hostname.length);
  95. addressAsChar[hostname.length] = 0;
  96. char port[6];
  97. sprintf(port, "%u", networkPort);
  98. if(UA_getaddrinfo(addressAsChar, port, &hints, &requestResult) != 0) {
  99. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  100. "PubSub Connection creation failed. Internal error.");
  101. UA_free(channelDataUDPMC);
  102. UA_free(newChannel);
  103. return NULL;
  104. }
  105. //check if the ip address is a multicast address
  106. if(requestResult->ai_family == PF_INET){
  107. struct in_addr imr_interface;
  108. UA_inet_pton(AF_INET, addressAsChar, &imr_interface);
  109. if((UA_ntohl(imr_interface.s_addr) & 0xF0000000) != 0xE0000000){
  110. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  111. "PubSub Connection creation failed. No multicast address.");
  112. }
  113. } else {
  114. //TODO check if ipv6 addrr is multicast address.
  115. }
  116. for(rp = requestResult; rp != NULL; rp = rp->ai_next){
  117. newChannel->sockfd = UA_socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  118. if(newChannel->sockfd != UA_INVALID_SOCKET){
  119. break; /*success*/
  120. }
  121. }
  122. if(!rp){
  123. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  124. "PubSub Connection creation failed. Internal error.");
  125. UA_freeaddrinfo(requestResult);
  126. UA_free(channelDataUDPMC);
  127. UA_free(newChannel);
  128. return NULL;
  129. }
  130. channelDataUDPMC->ai_family = rp->ai_family;
  131. channelDataUDPMC->ai_addr = (struct sockaddr_storage *) UA_calloc(1, sizeof(struct sockaddr_storage));
  132. if(!channelDataUDPMC->ai_addr){
  133. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  134. "PubSub Connection creation failed. Out of memory.");
  135. UA_close(newChannel->sockfd);
  136. UA_freeaddrinfo(requestResult);
  137. UA_free(channelDataUDPMC);
  138. UA_free(newChannel);
  139. return NULL;
  140. }
  141. memcpy(channelDataUDPMC->ai_addr, rp->ai_addr, sizeof(*rp->ai_addr));
  142. //link channel and internal channel data
  143. newChannel->handle = channelDataUDPMC;
  144. //Set loop back data to your host
  145. #if UA_IPV6
  146. if(UA_setsockopt(newChannel->sockfd,
  147. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  148. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_LOOP : IP_MULTICAST_LOOP,
  149. (const char *)&channelDataUDPMC->enableLoopback, sizeof (channelDataUDPMC->enableLoopback))
  150. #else
  151. if(UA_setsockopt(newChannel->sockfd,
  152. IPPROTO_IP,
  153. IP_MULTICAST_LOOP,
  154. (const char *)&channelDataUDPMC->enableLoopback, sizeof (channelDataUDPMC->enableLoopback))
  155. #endif
  156. < 0) {
  157. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  158. "PubSub Connection creation failed. Loopback setup failed.");
  159. UA_close(newChannel->sockfd);
  160. UA_freeaddrinfo(requestResult);
  161. UA_free(channelDataUDPMC);
  162. UA_free(newChannel);
  163. return NULL;
  164. }
  165. //Set Time to live (TTL). Value of 1 prevent forward beyond the local network.
  166. #if UA_IPV6
  167. if(UA_setsockopt(newChannel->sockfd,
  168. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  169. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_HOPS : IP_MULTICAST_TTL,
  170. (const char *)&channelDataUDPMC->messageTTL, sizeof(channelDataUDPMC->messageTTL))
  171. #else
  172. if(UA_setsockopt(newChannel->sockfd,
  173. IPPROTO_IP,
  174. IP_MULTICAST_TTL,
  175. (const char *)&channelDataUDPMC->messageTTL, sizeof(channelDataUDPMC->messageTTL))
  176. #endif
  177. < 0) {
  178. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  179. "PubSub Connection creation problem. Time to live setup failed.");
  180. }
  181. //Set reuse address -> enables sharing of the same listening address on different sockets.
  182. if(channelDataUDPMC->enableReuse){
  183. int enableReuse = 1;
  184. if(UA_setsockopt(newChannel->sockfd,
  185. SOL_SOCKET, SO_REUSEADDR,
  186. (const char*)&enableReuse, sizeof(enableReuse)) < 0){
  187. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  188. "PubSub Connection creation problem. Reuse address setup failed.");
  189. }
  190. }
  191. //Set the physical interface for outgoing traffic
  192. if(address.networkInterface.length > 0){
  193. UA_STACKARRAY(char, interfaceAsChar, sizeof(char) * address.networkInterface.length + 1);
  194. memcpy(interfaceAsChar, address.networkInterface.data, address.networkInterface.length);
  195. interfaceAsChar[address.networkInterface.length] = 0;
  196. enum{
  197. IPv4,
  198. #if UA_IPV6
  199. IPv6,
  200. #endif
  201. INVALID
  202. } ipVersion;
  203. union {
  204. struct ip_mreq ipv4;
  205. #if UA_IPV6
  206. struct ipv6_mreq ipv6;
  207. #endif
  208. } group;
  209. if(UA_inet_pton(AF_INET, interfaceAsChar, &group.ipv4.imr_interface)){
  210. ipVersion = IPv4;
  211. #if UA_IPV6
  212. } else if (UA_inet_pton(AF_INET6, interfaceAsChar, &group.ipv6.ipv6mr_multiaddr)){
  213. group.ipv6.ipv6mr_interface = UA_if_nametoindex(interfaceAsChar);
  214. ipVersion = IPv6;
  215. #endif
  216. } else {
  217. ipVersion = INVALID;
  218. }
  219. if(ipVersion == INVALID ||
  220. #if UA_IPV6
  221. UA_setsockopt(newChannel->sockfd,
  222. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  223. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_IF : IP_MULTICAST_IF,
  224. ipVersion == IPv6 ? (const void *) &group.ipv6.ipv6mr_interface : &group.ipv4.imr_interface,
  225. ipVersion == IPv6 ? sizeof(group.ipv6.ipv6mr_interface) : sizeof(struct in_addr))
  226. #else
  227. UA_setsockopt(newChannel->sockfd,
  228. IPPROTO_IP,
  229. IP_MULTICAST_IF,
  230. &group.ipv4.imr_interface,
  231. sizeof(struct in_addr))
  232. #endif
  233. < 0) {
  234. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  235. "PubSub Connection creation problem. Interface selection failed.");
  236. };
  237. }
  238. UA_freeaddrinfo(requestResult);
  239. newChannel->state = UA_PUBSUB_CHANNEL_PUB;
  240. return newChannel;
  241. }
  242. /**
  243. * Subscribe to a given address.
  244. *
  245. * @return UA_STATUSCODE_GOOD on success
  246. */
  247. static UA_StatusCode
  248. UA_PubSubChannelUDPMC_regist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings,
  249. void (*notUsedHere)(UA_ByteString *encodedBuffer, UA_ByteString *topic)) {
  250. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_RDY)){
  251. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  252. return UA_STATUSCODE_BADINTERNALERROR;
  253. }
  254. UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
  255. if(connectionConfig->ai_family == PF_INET){//IPv4 handling
  256. struct sockaddr_in addr;
  257. memcpy(&addr, connectionConfig->ai_addr, sizeof(struct sockaddr_in));
  258. addr.sin_addr.s_addr = INADDR_ANY;
  259. if (UA_bind(channel->sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0){
  260. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  261. return UA_STATUSCODE_BADINTERNALERROR;
  262. }
  263. struct ip_mreq groupV4;
  264. memcpy(&groupV4.imr_multiaddr, &((const struct sockaddr_in *)connectionConfig->ai_addr)->sin_addr, sizeof(struct ip_mreq));
  265. groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);
  266. //multihomed hosts can join several groups on different IF, INADDR_ANY -> kernel decides
  267. if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &groupV4, sizeof(groupV4)) != 0) {
  268. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  269. "PubSub Connection not on multicast");
  270. }
  271. #if UA_IPV6
  272. } else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
  273. //TODO implement regist for IPv6
  274. #endif
  275. } else {
  276. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  277. return UA_STATUSCODE_BADINTERNALERROR;
  278. }
  279. return UA_STATUSCODE_GOOD;
  280. }
  281. /**
  282. * Remove current subscription.
  283. *
  284. * @return UA_STATUSCODE_GOOD on success
  285. */
  286. static UA_StatusCode
  287. UA_PubSubChannelUDPMC_unregist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings) {
  288. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB_SUB || channel->state == UA_PUBSUB_CHANNEL_SUB)){
  289. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  290. return UA_STATUSCODE_BADINTERNALERROR;
  291. }
  292. UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
  293. if(connectionConfig->ai_family == PF_INET){//IPv4 handling
  294. struct ip_mreq groupV4;
  295. memcpy(&groupV4.imr_multiaddr, &((const struct sockaddr_in *)connectionConfig->ai_addr)->sin_addr, sizeof(struct ip_mreq));
  296. groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);
  297. if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *) &groupV4, sizeof(groupV4)) != 0){
  298. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  299. return UA_STATUSCODE_BADINTERNALERROR;
  300. }
  301. #if UA_IPV6
  302. } else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
  303. //TODO implement unregist for IPv6
  304. #endif
  305. } else {
  306. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  307. return UA_STATUSCODE_BADINTERNALERROR;
  308. }
  309. return UA_STATUSCODE_GOOD;
  310. }
  311. /**
  312. * Send messages to the connection defined address
  313. *
  314. * @return UA_STATUSCODE_GOOD if success
  315. */
  316. static UA_StatusCode
  317. UA_PubSubChannelUDPMC_send(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettigns, const UA_ByteString *buf) {
  318. UA_PubSubChannelDataUDPMC *channelConfigUDPMC = (UA_PubSubChannelDataUDPMC *) channel->handle;
  319. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_PUB_SUB)){
  320. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection sending failed. Invalid state.");
  321. return UA_STATUSCODE_BADINTERNALERROR;
  322. }
  323. //TODO evalute: chunk messages or check against MTU?
  324. long nWritten = 0;
  325. while (nWritten < (long)buf->length) {
  326. long n = (long)UA_sendto(channel->sockfd, buf->data, buf->length, 0,
  327. (struct sockaddr *) channelConfigUDPMC->ai_addr, sizeof(struct sockaddr_storage));
  328. if(n == -1L) {
  329. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection sending failed.");
  330. return UA_STATUSCODE_BADINTERNALERROR;
  331. }
  332. nWritten += n;
  333. }
  334. return UA_STATUSCODE_GOOD;
  335. }
  336. /**
  337. * Receive messages. The regist function should be called before.
  338. *
  339. * @param timeout in usec | on windows platforms are only multiples of 1000usec possible
  340. * @return
  341. */
  342. static UA_StatusCode
  343. UA_PubSubChannelUDPMC_receive(UA_PubSubChannel *channel, UA_ByteString *message, UA_ExtensionObject *transportSettigns, UA_UInt32 timeout){
  344. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_PUB_SUB)) {
  345. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection receive failed. Invalid state.");
  346. return UA_STATUSCODE_BADINTERNALERROR;
  347. }
  348. UA_PubSubChannelDataUDPMC *channelConfigUDPMC = (UA_PubSubChannelDataUDPMC *) channel->handle;
  349. if(timeout > 0) {
  350. fd_set fdset;
  351. FD_ZERO(&fdset);
  352. UA_fd_set(channel->sockfd, &fdset);
  353. struct timeval tmptv = {(long int)(timeout / 1000000),
  354. (long int)(timeout % 1000000)};
  355. int resultsize = UA_select(channel->sockfd+1, &fdset, NULL,
  356. NULL, &tmptv);
  357. if(resultsize == 0) {
  358. message->length = 0;
  359. return UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
  360. }
  361. if (resultsize == -1) {
  362. message->length = 0;
  363. return UA_STATUSCODE_BADINTERNALERROR;
  364. }
  365. }
  366. if(channelConfigUDPMC->ai_family == PF_INET){
  367. ssize_t messageLength;
  368. messageLength = UA_recvfrom(channel->sockfd, message->data, message->length, 0, NULL, NULL);
  369. if(messageLength > 0){
  370. message->length = (size_t) messageLength;
  371. } else {
  372. message->length = 0;
  373. }
  374. #if UA_IPV6
  375. } else {
  376. //TODO implement recieve for IPv6
  377. #endif
  378. }
  379. return UA_STATUSCODE_GOOD;
  380. }
  381. /**
  382. * Close channel and free the channel data.
  383. *
  384. * @return UA_STATUSCODE_GOOD if success
  385. */
  386. static UA_StatusCode
  387. UA_PubSubChannelUDPMC_close(UA_PubSubChannel *channel) {
  388. if(UA_close(channel->sockfd) != 0){
  389. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection delete failed.");
  390. return UA_STATUSCODE_BADINTERNALERROR;
  391. }
  392. UA_deinitialize_architecture_network();
  393. //cleanup the internal NetworkLayer data
  394. UA_PubSubChannelDataUDPMC *networkLayerData = (UA_PubSubChannelDataUDPMC *) channel->handle;
  395. UA_free(networkLayerData->ai_addr);
  396. UA_free(networkLayerData);
  397. UA_free(channel);
  398. return UA_STATUSCODE_GOOD;
  399. }
  400. /**
  401. * Generate a new channel. based on the given configuration.
  402. *
  403. * @param connectionConfig connection configuration
  404. * @return ref to created channel, NULL on error
  405. */
  406. static UA_PubSubChannel *
  407. TransportLayerUDPMC_addChannel(UA_PubSubConnectionConfig *connectionConfig) {
  408. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "PubSub channel requested");
  409. UA_PubSubChannel * pubSubChannel = UA_PubSubChannelUDPMC_open(connectionConfig);
  410. if(pubSubChannel){
  411. pubSubChannel->regist = UA_PubSubChannelUDPMC_regist;
  412. pubSubChannel->unregist = UA_PubSubChannelUDPMC_unregist;
  413. pubSubChannel->send = UA_PubSubChannelUDPMC_send;
  414. pubSubChannel->receive = UA_PubSubChannelUDPMC_receive;
  415. pubSubChannel->close = UA_PubSubChannelUDPMC_close;
  416. pubSubChannel->connectionConfig = connectionConfig;
  417. }
  418. return pubSubChannel;
  419. }
  420. //UDPMC channel factory
  421. UA_PubSubTransportLayer
  422. UA_PubSubTransportLayerUDPMP() {
  423. UA_PubSubTransportLayer pubSubTransportLayer;
  424. pubSubTransportLayer.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  425. pubSubTransportLayer.createPubSubChannel = &TransportLayerUDPMC_addChannel;
  426. return pubSubTransportLayer;
  427. }