18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * include/uapi/linux/tipc_config.h: Header for TIPC configuration interface 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2003-2006, Ericsson AB 68c2ecf20Sopenharmony_ci * Copyright (c) 2005-2007, 2010-2011, Wind River Systems 78c2ecf20Sopenharmony_ci * All rights reserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 108c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 148c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 158c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 168c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 178c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 188c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 198c2ecf20Sopenharmony_ci * this software without specific prior written permission. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 228c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 238c2ecf20Sopenharmony_ci * Software Foundation. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 268c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 278c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 288c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 298c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 308c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 318c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 328c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 338c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 348c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 358c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#ifndef _LINUX_TIPC_CONFIG_H_ 398c2ecf20Sopenharmony_ci#define _LINUX_TIPC_CONFIG_H_ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#include <linux/types.h> 428c2ecf20Sopenharmony_ci#include <linux/string.h> 438c2ecf20Sopenharmony_ci#include <linux/tipc.h> 448c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#ifndef __KERNEL__ 478c2ecf20Sopenharmony_ci#include <arpa/inet.h> /* for ntohs etc. */ 488c2ecf20Sopenharmony_ci#endif 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * Configuration 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * All configuration management messaging involves sending a request message 548c2ecf20Sopenharmony_ci * to the TIPC configuration service on a node, which sends a reply message 558c2ecf20Sopenharmony_ci * back. (In the future multi-message replies may be supported.) 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * Both request and reply messages consist of a transport header and payload. 588c2ecf20Sopenharmony_ci * The transport header contains info about the desired operation; 598c2ecf20Sopenharmony_ci * the payload consists of zero or more type/length/value (TLV) items 608c2ecf20Sopenharmony_ci * which specify parameters or results for the operation. 618c2ecf20Sopenharmony_ci * 628c2ecf20Sopenharmony_ci * For many operations, the request and reply messages have a fixed number 638c2ecf20Sopenharmony_ci * of TLVs (usually zero or one); however, some reply messages may return 648c2ecf20Sopenharmony_ci * a variable number of TLVs. A failed request is denoted by the presence 658c2ecf20Sopenharmony_ci * of an "error string" TLV in the reply message instead of the TLV(s) the 668c2ecf20Sopenharmony_ci * reply should contain if the request succeeds. 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci * Public commands: 718c2ecf20Sopenharmony_ci * May be issued by any process. 728c2ecf20Sopenharmony_ci * Accepted by own node, or by remote node only if remote management enabled. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define TIPC_CMD_NOOP 0x0000 /* tx none, rx none */ 768c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_NODES 0x0001 /* tx net_addr, rx node_info(s) */ 778c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MEDIA_NAMES 0x0002 /* tx none, rx media_name(s) */ 788c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_BEARER_NAMES 0x0003 /* tx none, rx bearer_name(s) */ 798c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_LINKS 0x0004 /* tx net_addr, rx link_info(s) */ 808c2ecf20Sopenharmony_ci#define TIPC_CMD_SHOW_NAME_TABLE 0x0005 /* tx name_tbl_query, rx ultra_string */ 818c2ecf20Sopenharmony_ci#define TIPC_CMD_SHOW_PORTS 0x0006 /* tx none, rx ultra_string */ 828c2ecf20Sopenharmony_ci#define TIPC_CMD_SHOW_LINK_STATS 0x000B /* tx link_name, rx ultra_string */ 838c2ecf20Sopenharmony_ci#define TIPC_CMD_SHOW_STATS 0x000F /* tx unsigned, rx ultra_string */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* 868c2ecf20Sopenharmony_ci * Protected commands: 878c2ecf20Sopenharmony_ci * May only be issued by "network administration capable" process. 888c2ecf20Sopenharmony_ci * Accepted by own node, or by remote node only if remote management enabled 898c2ecf20Sopenharmony_ci * and this node is zone manager. 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_REMOTE_MNG 0x4003 /* tx none, rx unsigned */ 938c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_PORTS 0x4004 /* tx none, rx unsigned */ 948c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_PUBL 0x4005 /* obsoleted */ 958c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_SUBSCR 0x4006 /* obsoleted */ 968c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_ZONES 0x4007 /* obsoleted */ 978c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_CLUSTERS 0x4008 /* obsoleted */ 988c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_NODES 0x4009 /* obsoleted */ 998c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_MAX_SLAVES 0x400A /* obsoleted */ 1008c2ecf20Sopenharmony_ci#define TIPC_CMD_GET_NETID 0x400B /* tx none, rx unsigned */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define TIPC_CMD_ENABLE_BEARER 0x4101 /* tx bearer_config, rx none */ 1038c2ecf20Sopenharmony_ci#define TIPC_CMD_DISABLE_BEARER 0x4102 /* tx bearer_name, rx none */ 1048c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_LINK_TOL 0x4107 /* tx link_config, rx none */ 1058c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_LINK_PRI 0x4108 /* tx link_config, rx none */ 1068c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_LINK_WINDOW 0x4109 /* tx link_config, rx none */ 1078c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_LOG_SIZE 0x410A /* obsoleted */ 1088c2ecf20Sopenharmony_ci#define TIPC_CMD_DUMP_LOG 0x410B /* obsoleted */ 1098c2ecf20Sopenharmony_ci#define TIPC_CMD_RESET_LINK_STATS 0x410C /* tx link_name, rx none */ 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/* 1128c2ecf20Sopenharmony_ci * Private commands: 1138c2ecf20Sopenharmony_ci * May only be issued by "network administration capable" process. 1148c2ecf20Sopenharmony_ci * Accepted by own node only; cannot be used on a remote node. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_NODE_ADDR 0x8001 /* tx net_addr, rx none */ 1188c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_REMOTE_MNG 0x8003 /* tx unsigned, rx none */ 1198c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_PORTS 0x8004 /* tx unsigned, rx none */ 1208c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_PUBL 0x8005 /* obsoleted */ 1218c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_SUBSCR 0x8006 /* obsoleted */ 1228c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_ZONES 0x8007 /* obsoleted */ 1238c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_CLUSTERS 0x8008 /* obsoleted */ 1248c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_NODES 0x8009 /* obsoleted */ 1258c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_MAX_SLAVES 0x800A /* obsoleted */ 1268c2ecf20Sopenharmony_ci#define TIPC_CMD_SET_NETID 0x800B /* tx unsigned, rx none */ 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* 1298c2ecf20Sopenharmony_ci * Reserved commands: 1308c2ecf20Sopenharmony_ci * May not be issued by any process. 1318c2ecf20Sopenharmony_ci * Used internally by TIPC. 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define TIPC_CMD_NOT_NET_ADMIN 0xC001 /* tx none, rx none */ 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* 1378c2ecf20Sopenharmony_ci * TLV types defined for TIPC 1388c2ecf20Sopenharmony_ci */ 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define TIPC_TLV_NONE 0 /* no TLV present */ 1418c2ecf20Sopenharmony_ci#define TIPC_TLV_VOID 1 /* empty TLV (0 data bytes)*/ 1428c2ecf20Sopenharmony_ci#define TIPC_TLV_UNSIGNED 2 /* 32-bit integer */ 1438c2ecf20Sopenharmony_ci#define TIPC_TLV_STRING 3 /* char[128] (max) */ 1448c2ecf20Sopenharmony_ci#define TIPC_TLV_LARGE_STRING 4 /* char[2048] (max) */ 1458c2ecf20Sopenharmony_ci#define TIPC_TLV_ULTRA_STRING 5 /* char[32768] (max) */ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define TIPC_TLV_ERROR_STRING 16 /* char[128] containing "error code" */ 1488c2ecf20Sopenharmony_ci#define TIPC_TLV_NET_ADDR 17 /* 32-bit integer denoting <Z.C.N> */ 1498c2ecf20Sopenharmony_ci#define TIPC_TLV_MEDIA_NAME 18 /* char[TIPC_MAX_MEDIA_NAME] */ 1508c2ecf20Sopenharmony_ci#define TIPC_TLV_BEARER_NAME 19 /* char[TIPC_MAX_BEARER_NAME] */ 1518c2ecf20Sopenharmony_ci#define TIPC_TLV_LINK_NAME 20 /* char[TIPC_MAX_LINK_NAME] */ 1528c2ecf20Sopenharmony_ci#define TIPC_TLV_NODE_INFO 21 /* struct tipc_node_info */ 1538c2ecf20Sopenharmony_ci#define TIPC_TLV_LINK_INFO 22 /* struct tipc_link_info */ 1548c2ecf20Sopenharmony_ci#define TIPC_TLV_BEARER_CONFIG 23 /* struct tipc_bearer_config */ 1558c2ecf20Sopenharmony_ci#define TIPC_TLV_LINK_CONFIG 24 /* struct tipc_link_config */ 1568c2ecf20Sopenharmony_ci#define TIPC_TLV_NAME_TBL_QUERY 25 /* struct tipc_name_table_query */ 1578c2ecf20Sopenharmony_ci#define TIPC_TLV_PORT_REF 26 /* 32-bit port reference */ 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/* 1608c2ecf20Sopenharmony_ci * Link priority limits (min, default, max, media default) 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci#define TIPC_MIN_LINK_PRI 0 1648c2ecf20Sopenharmony_ci#define TIPC_DEF_LINK_PRI 10 1658c2ecf20Sopenharmony_ci#define TIPC_MAX_LINK_PRI 31 1668c2ecf20Sopenharmony_ci#define TIPC_MEDIA_LINK_PRI (TIPC_MAX_LINK_PRI + 1) 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci/* 1698c2ecf20Sopenharmony_ci * Link tolerance limits (min, default, max), in ms 1708c2ecf20Sopenharmony_ci */ 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#define TIPC_MIN_LINK_TOL 50 1738c2ecf20Sopenharmony_ci#define TIPC_DEF_LINK_TOL 1500 1748c2ecf20Sopenharmony_ci#define TIPC_MAX_LINK_TOL 30000 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#if (TIPC_MIN_LINK_TOL < 16) 1778c2ecf20Sopenharmony_ci#error "TIPC_MIN_LINK_TOL is too small (abort limit may be NaN)" 1788c2ecf20Sopenharmony_ci#endif 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* 1818c2ecf20Sopenharmony_ci * Link window limits (min, default, max), in packets 1828c2ecf20Sopenharmony_ci */ 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#define TIPC_MIN_LINK_WIN 16 1858c2ecf20Sopenharmony_ci#define TIPC_DEF_LINK_WIN 50 1868c2ecf20Sopenharmony_ci#define TIPC_MAX_LINK_WIN 8191 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* 1898c2ecf20Sopenharmony_ci * Default MTU for UDP media 1908c2ecf20Sopenharmony_ci */ 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#define TIPC_DEF_LINK_UDP_MTU 14000 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistruct tipc_node_info { 1958c2ecf20Sopenharmony_ci __be32 addr; /* network address of node */ 1968c2ecf20Sopenharmony_ci __be32 up; /* 0=down, 1= up */ 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistruct tipc_link_info { 2008c2ecf20Sopenharmony_ci __be32 dest; /* network address of peer node */ 2018c2ecf20Sopenharmony_ci __be32 up; /* 0=down, 1=up */ 2028c2ecf20Sopenharmony_ci char str[TIPC_MAX_LINK_NAME]; /* link name */ 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistruct tipc_bearer_config { 2068c2ecf20Sopenharmony_ci __be32 priority; /* Range [1,31]. Override per link */ 2078c2ecf20Sopenharmony_ci __be32 disc_domain; /* <Z.C.N> describing desired nodes */ 2088c2ecf20Sopenharmony_ci char name[TIPC_MAX_BEARER_NAME]; 2098c2ecf20Sopenharmony_ci}; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistruct tipc_link_config { 2128c2ecf20Sopenharmony_ci __be32 value; 2138c2ecf20Sopenharmony_ci char name[TIPC_MAX_LINK_NAME]; 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci#define TIPC_NTQ_ALLTYPES 0x80000000 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistruct tipc_name_table_query { 2198c2ecf20Sopenharmony_ci __be32 depth; /* 1:type, 2:+name info, 3:+port info, 4+:+debug info */ 2208c2ecf20Sopenharmony_ci __be32 type; /* {t,l,u} info ignored if high bit of "depth" is set */ 2218c2ecf20Sopenharmony_ci __be32 lowbound; /* (i.e. displays all entries of name table) */ 2228c2ecf20Sopenharmony_ci __be32 upbound; 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci/* 2268c2ecf20Sopenharmony_ci * The error string TLV is a null-terminated string describing the cause 2278c2ecf20Sopenharmony_ci * of the request failure. To simplify error processing (and to save space) 2288c2ecf20Sopenharmony_ci * the first character of the string can be a special error code character 2298c2ecf20Sopenharmony_ci * (lying by the range 0x80 to 0xFF) which represents a pre-defined reason. 2308c2ecf20Sopenharmony_ci */ 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci#define TIPC_CFG_TLV_ERROR "\x80" /* request contains incorrect TLV(s) */ 2338c2ecf20Sopenharmony_ci#define TIPC_CFG_NOT_NET_ADMIN "\x81" /* must be network administrator */ 2348c2ecf20Sopenharmony_ci#define TIPC_CFG_NOT_ZONE_MSTR "\x82" /* must be zone master */ 2358c2ecf20Sopenharmony_ci#define TIPC_CFG_NO_REMOTE "\x83" /* remote management not enabled */ 2368c2ecf20Sopenharmony_ci#define TIPC_CFG_NOT_SUPPORTED "\x84" /* request is not supported by TIPC */ 2378c2ecf20Sopenharmony_ci#define TIPC_CFG_INVALID_VALUE "\x85" /* request has invalid argument value */ 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci/* 2408c2ecf20Sopenharmony_ci * A TLV consists of a descriptor, followed by the TLV value. 2418c2ecf20Sopenharmony_ci * TLV descriptor fields are stored in network byte order; 2428c2ecf20Sopenharmony_ci * TLV values must also be stored in network byte order (where applicable). 2438c2ecf20Sopenharmony_ci * TLV descriptors must be aligned to addresses which are multiple of 4, 2448c2ecf20Sopenharmony_ci * so up to 3 bytes of padding may exist at the end of the TLV value area. 2458c2ecf20Sopenharmony_ci * There must not be any padding between the TLV descriptor and its value. 2468c2ecf20Sopenharmony_ci */ 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cistruct tlv_desc { 2498c2ecf20Sopenharmony_ci __be16 tlv_len; /* TLV length (descriptor + value) */ 2508c2ecf20Sopenharmony_ci __be16 tlv_type; /* TLV identifier */ 2518c2ecf20Sopenharmony_ci}; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci#define TLV_ALIGNTO 4 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci#define TLV_ALIGN(datalen) (((datalen)+(TLV_ALIGNTO-1)) & ~(TLV_ALIGNTO-1)) 2568c2ecf20Sopenharmony_ci#define TLV_LENGTH(datalen) (sizeof(struct tlv_desc) + (datalen)) 2578c2ecf20Sopenharmony_ci#define TLV_SPACE(datalen) (TLV_ALIGN(TLV_LENGTH(datalen))) 2588c2ecf20Sopenharmony_ci#define TLV_DATA(tlv) ((void *)((char *)(tlv) + TLV_LENGTH(0))) 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_cistatic inline int TLV_OK(const void *tlv, __u16 space) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci /* 2638c2ecf20Sopenharmony_ci * Would also like to check that "tlv" is a multiple of 4, 2648c2ecf20Sopenharmony_ci * but don't know how to do this in a portable way. 2658c2ecf20Sopenharmony_ci * - Tried doing (!(tlv & (TLV_ALIGNTO-1))), but GCC compiler 2668c2ecf20Sopenharmony_ci * won't allow binary "&" with a pointer. 2678c2ecf20Sopenharmony_ci * - Tried casting "tlv" to integer type, but causes warning about size 2688c2ecf20Sopenharmony_ci * mismatch when pointer is bigger than chosen type (int, long, ...). 2698c2ecf20Sopenharmony_ci */ 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci return (space >= TLV_SPACE(0)) && 2728c2ecf20Sopenharmony_ci (ntohs(((struct tlv_desc *)tlv)->tlv_len) <= space); 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_cistatic inline int TLV_CHECK(const void *tlv, __u16 space, __u16 exp_type) 2768c2ecf20Sopenharmony_ci{ 2778c2ecf20Sopenharmony_ci return TLV_OK(tlv, space) && 2788c2ecf20Sopenharmony_ci (ntohs(((struct tlv_desc *)tlv)->tlv_type) == exp_type); 2798c2ecf20Sopenharmony_ci} 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_cistatic inline int TLV_GET_LEN(struct tlv_desc *tlv) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci return ntohs(tlv->tlv_len); 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic inline void TLV_SET_LEN(struct tlv_desc *tlv, __u16 len) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci tlv->tlv_len = htons(len); 2898c2ecf20Sopenharmony_ci} 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistatic inline int TLV_CHECK_TYPE(struct tlv_desc *tlv, __u16 type) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci return (ntohs(tlv->tlv_type) == type); 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistatic inline void TLV_SET_TYPE(struct tlv_desc *tlv, __u16 type) 2978c2ecf20Sopenharmony_ci{ 2988c2ecf20Sopenharmony_ci tlv->tlv_type = htons(type); 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistatic inline int TLV_SET(void *tlv, __u16 type, void *data, __u16 len) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci struct tlv_desc *tlv_ptr; 3048c2ecf20Sopenharmony_ci int tlv_len; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci tlv_len = TLV_LENGTH(len); 3078c2ecf20Sopenharmony_ci tlv_ptr = (struct tlv_desc *)tlv; 3088c2ecf20Sopenharmony_ci tlv_ptr->tlv_type = htons(type); 3098c2ecf20Sopenharmony_ci tlv_ptr->tlv_len = htons(tlv_len); 3108c2ecf20Sopenharmony_ci if (len && data) { 3118c2ecf20Sopenharmony_ci memcpy(TLV_DATA(tlv_ptr), data, len); 3128c2ecf20Sopenharmony_ci memset((char *)TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) - tlv_len); 3138c2ecf20Sopenharmony_ci } 3148c2ecf20Sopenharmony_ci return TLV_SPACE(len); 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci/* 3188c2ecf20Sopenharmony_ci * A TLV list descriptor simplifies processing of messages 3198c2ecf20Sopenharmony_ci * containing multiple TLVs. 3208c2ecf20Sopenharmony_ci */ 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistruct tlv_list_desc { 3238c2ecf20Sopenharmony_ci struct tlv_desc *tlv_ptr; /* ptr to current TLV */ 3248c2ecf20Sopenharmony_ci __u32 tlv_space; /* # bytes from curr TLV to list end */ 3258c2ecf20Sopenharmony_ci}; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_cistatic inline void TLV_LIST_INIT(struct tlv_list_desc *list, 3288c2ecf20Sopenharmony_ci void *data, __u32 space) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci list->tlv_ptr = (struct tlv_desc *)data; 3318c2ecf20Sopenharmony_ci list->tlv_space = space; 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistatic inline int TLV_LIST_EMPTY(struct tlv_list_desc *list) 3358c2ecf20Sopenharmony_ci{ 3368c2ecf20Sopenharmony_ci return (list->tlv_space == 0); 3378c2ecf20Sopenharmony_ci} 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistatic inline int TLV_LIST_CHECK(struct tlv_list_desc *list, __u16 exp_type) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci return TLV_CHECK(list->tlv_ptr, list->tlv_space, exp_type); 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_cistatic inline void *TLV_LIST_DATA(struct tlv_list_desc *list) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci return TLV_DATA(list->tlv_ptr); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic inline void TLV_LIST_STEP(struct tlv_list_desc *list) 3508c2ecf20Sopenharmony_ci{ 3518c2ecf20Sopenharmony_ci __u16 tlv_space = TLV_ALIGN(ntohs(list->tlv_ptr->tlv_len)); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci list->tlv_ptr = (struct tlv_desc *)((char *)list->tlv_ptr + tlv_space); 3548c2ecf20Sopenharmony_ci list->tlv_space -= tlv_space; 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci/* 3588c2ecf20Sopenharmony_ci * Configuration messages exchanged via NETLINK_GENERIC use the following 3598c2ecf20Sopenharmony_ci * family id, name, version and command. 3608c2ecf20Sopenharmony_ci */ 3618c2ecf20Sopenharmony_ci#define TIPC_GENL_NAME "TIPC" 3628c2ecf20Sopenharmony_ci#define TIPC_GENL_VERSION 0x1 3638c2ecf20Sopenharmony_ci#define TIPC_GENL_CMD 0x1 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci/* 3668c2ecf20Sopenharmony_ci * TIPC specific header used in NETLINK_GENERIC requests. 3678c2ecf20Sopenharmony_ci */ 3688c2ecf20Sopenharmony_cistruct tipc_genlmsghdr { 3698c2ecf20Sopenharmony_ci __u32 dest; /* Destination address */ 3708c2ecf20Sopenharmony_ci __u16 cmd; /* Command */ 3718c2ecf20Sopenharmony_ci __u16 reserved; /* Unused */ 3728c2ecf20Sopenharmony_ci}; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci#define TIPC_GENL_HDRLEN NLMSG_ALIGN(sizeof(struct tipc_genlmsghdr)) 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci/* 3778c2ecf20Sopenharmony_ci * Configuration messages exchanged via TIPC sockets use the TIPC configuration 3788c2ecf20Sopenharmony_ci * message header, which is defined below. This structure is analogous 3798c2ecf20Sopenharmony_ci * to the Netlink message header, but fields are stored in network byte order 3808c2ecf20Sopenharmony_ci * and no padding is permitted between the header and the message data 3818c2ecf20Sopenharmony_ci * that follows. 3828c2ecf20Sopenharmony_ci */ 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistruct tipc_cfg_msg_hdr { 3858c2ecf20Sopenharmony_ci __be32 tcm_len; /* Message length (including header) */ 3868c2ecf20Sopenharmony_ci __be16 tcm_type; /* Command type */ 3878c2ecf20Sopenharmony_ci __be16 tcm_flags; /* Additional flags */ 3888c2ecf20Sopenharmony_ci char tcm_reserved[8]; /* Unused */ 3898c2ecf20Sopenharmony_ci}; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci#define TCM_F_REQUEST 0x1 /* Flag: Request message */ 3928c2ecf20Sopenharmony_ci#define TCM_F_MORE 0x2 /* Flag: Message to be continued */ 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci#define TCM_ALIGN(datalen) (((datalen)+3) & ~3) 3958c2ecf20Sopenharmony_ci#define TCM_LENGTH(datalen) (sizeof(struct tipc_cfg_msg_hdr) + datalen) 3968c2ecf20Sopenharmony_ci#define TCM_SPACE(datalen) (TCM_ALIGN(TCM_LENGTH(datalen))) 3978c2ecf20Sopenharmony_ci#define TCM_DATA(tcm_hdr) ((void *)((char *)(tcm_hdr) + TCM_LENGTH(0))) 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_cistatic inline int TCM_SET(void *msg, __u16 cmd, __u16 flags, 4008c2ecf20Sopenharmony_ci void *data, __u16 data_len) 4018c2ecf20Sopenharmony_ci{ 4028c2ecf20Sopenharmony_ci struct tipc_cfg_msg_hdr *tcm_hdr; 4038c2ecf20Sopenharmony_ci int msg_len; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci msg_len = TCM_LENGTH(data_len); 4068c2ecf20Sopenharmony_ci tcm_hdr = (struct tipc_cfg_msg_hdr *)msg; 4078c2ecf20Sopenharmony_ci tcm_hdr->tcm_len = htonl(msg_len); 4088c2ecf20Sopenharmony_ci tcm_hdr->tcm_type = htons(cmd); 4098c2ecf20Sopenharmony_ci tcm_hdr->tcm_flags = htons(flags); 4108c2ecf20Sopenharmony_ci if (data_len && data) { 4118c2ecf20Sopenharmony_ci memcpy(TCM_DATA(msg), data, data_len); 4128c2ecf20Sopenharmony_ci memset((char *)TCM_DATA(msg) + data_len, 0, TCM_SPACE(data_len) - msg_len); 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci return TCM_SPACE(data_len); 4158c2ecf20Sopenharmony_ci} 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci#endif 418