James Kuszmaul | 82f6c04 | 2021-01-17 11:30:16 -0800 | [diff] [blame^] | 1 | /** |
| 2 | * @file re_bfcp.h Interface to Binary Floor Control Protocol (BFCP) |
| 3 | * |
| 4 | * Copyright (C) 2010 Creytiv.com |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | /** BFCP Versions */ |
| 9 | enum { |
| 10 | BFCP_VER1 = 1, |
| 11 | BFCP_VER2 = 2, |
| 12 | }; |
| 13 | |
| 14 | /** BFCP Primitives */ |
| 15 | enum bfcp_prim { |
| 16 | BFCP_FLOOR_REQUEST = 1, |
| 17 | BFCP_FLOOR_RELEASE = 2, |
| 18 | BFCP_FLOOR_REQUEST_QUERY = 3, |
| 19 | BFCP_FLOOR_REQUEST_STATUS = 4, |
| 20 | BFCP_USER_QUERY = 5, |
| 21 | BFCP_USER_STATUS = 6, |
| 22 | BFCP_FLOOR_QUERY = 7, |
| 23 | BFCP_FLOOR_STATUS = 8, |
| 24 | BFCP_CHAIR_ACTION = 9, |
| 25 | BFCP_CHAIR_ACTION_ACK = 10, |
| 26 | BFCP_HELLO = 11, |
| 27 | BFCP_HELLO_ACK = 12, |
| 28 | BFCP_ERROR = 13, |
| 29 | BFCP_FLOOR_REQ_STATUS_ACK = 14, |
| 30 | BFCP_FLOOR_STATUS_ACK = 15, |
| 31 | BFCP_GOODBYE = 16, |
| 32 | BFCP_GOODBYE_ACK = 17, |
| 33 | }; |
| 34 | |
| 35 | /** BFCP Attributes */ |
| 36 | enum bfcp_attrib { |
| 37 | BFCP_BENEFICIARY_ID = 1, |
| 38 | BFCP_FLOOR_ID = 2, |
| 39 | BFCP_FLOOR_REQUEST_ID = 3, |
| 40 | BFCP_PRIORITY = 4, |
| 41 | BFCP_REQUEST_STATUS = 5, |
| 42 | BFCP_ERROR_CODE = 6, |
| 43 | BFCP_ERROR_INFO = 7, |
| 44 | BFCP_PART_PROV_INFO = 8, |
| 45 | BFCP_STATUS_INFO = 9, |
| 46 | BFCP_SUPPORTED_ATTRS = 10, |
| 47 | BFCP_SUPPORTED_PRIMS = 11, |
| 48 | BFCP_USER_DISP_NAME = 12, |
| 49 | BFCP_USER_URI = 13, |
| 50 | /* grouped: */ |
| 51 | BFCP_BENEFICIARY_INFO = 14, |
| 52 | BFCP_FLOOR_REQ_INFO = 15, |
| 53 | BFCP_REQUESTED_BY_INFO = 16, |
| 54 | BFCP_FLOOR_REQ_STATUS = 17, |
| 55 | BFCP_OVERALL_REQ_STATUS = 18, |
| 56 | |
| 57 | /** Mandatory Attribute */ |
| 58 | BFCP_MANDATORY = 1<<7, |
| 59 | /** Encode Handler */ |
| 60 | BFCP_ENCODE_HANDLER = 1<<8, |
| 61 | }; |
| 62 | |
| 63 | /** BFCP Request Status */ |
| 64 | enum bfcp_reqstat { |
| 65 | BFCP_PENDING = 1, |
| 66 | BFCP_ACCEPTED = 2, |
| 67 | BFCP_GRANTED = 3, |
| 68 | BFCP_DENIED = 4, |
| 69 | BFCP_CANCELLED = 5, |
| 70 | BFCP_RELEASED = 6, |
| 71 | BFCP_REVOKED = 7 |
| 72 | }; |
| 73 | |
| 74 | /** BFCP Error Codes */ |
| 75 | enum bfcp_err { |
| 76 | BFCP_CONF_NOT_EXIST = 1, |
| 77 | BFCP_USER_NOT_EXIST = 2, |
| 78 | BFCP_UNKNOWN_PRIM = 3, |
| 79 | BFCP_UNKNOWN_MAND_ATTR = 4, |
| 80 | BFCP_UNAUTH_OPERATION = 5, |
| 81 | BFCP_INVALID_FLOOR_ID = 6, |
| 82 | BFCP_FLOOR_REQ_ID_NOT_EXIST = 7, |
| 83 | BFCP_MAX_FLOOR_REQ_REACHED = 8, |
| 84 | BFCP_USE_TLS = 9, |
| 85 | BFCP_PARSE_ERROR = 10, |
| 86 | BFCP_USE_DTLS = 11, |
| 87 | BFCP_UNSUPPORTED_VERSION = 12, |
| 88 | BFCP_BAD_LENGTH = 13, |
| 89 | BFCP_GENERIC_ERROR = 14, |
| 90 | }; |
| 91 | |
| 92 | /** BFCP Priority */ |
| 93 | enum bfcp_priority { |
| 94 | BFCP_PRIO_LOWEST = 0, |
| 95 | BFCP_PRIO_LOW = 1, |
| 96 | BFCP_PRIO_NORMAL = 2, |
| 97 | BFCP_PRIO_HIGH = 3, |
| 98 | BFCP_PRIO_HIGHEST = 4 |
| 99 | }; |
| 100 | |
| 101 | /** BFCP Transport */ |
| 102 | enum bfcp_transp { |
| 103 | BFCP_UDP, |
| 104 | BFCP_DTLS, |
| 105 | }; |
| 106 | |
| 107 | /** BFCP Request Status */ |
| 108 | struct bfcp_reqstatus { |
| 109 | enum bfcp_reqstat status; |
| 110 | uint8_t qpos; |
| 111 | }; |
| 112 | |
| 113 | /** BFCP Error Code */ |
| 114 | struct bfcp_errcode { |
| 115 | enum bfcp_err code; |
| 116 | uint8_t *details; /* optional */ |
| 117 | size_t len; |
| 118 | }; |
| 119 | |
| 120 | /** BFCP Supported Attributes */ |
| 121 | struct bfcp_supattr { |
| 122 | enum bfcp_attrib *attrv; |
| 123 | size_t attrc; |
| 124 | }; |
| 125 | |
| 126 | /** BFCP Supported Primitives */ |
| 127 | struct bfcp_supprim { |
| 128 | enum bfcp_prim *primv; |
| 129 | size_t primc; |
| 130 | }; |
| 131 | |
| 132 | /** BFCP Attribute */ |
| 133 | struct bfcp_attr { |
| 134 | struct le le; |
| 135 | struct list attrl; |
| 136 | enum bfcp_attrib type; |
| 137 | bool mand; |
| 138 | union bfcp_union { |
| 139 | /* generic types */ |
| 140 | char *str; |
| 141 | uint16_t u16; |
| 142 | |
| 143 | /* actual attributes */ |
| 144 | uint16_t beneficiaryid; |
| 145 | uint16_t floorid; |
| 146 | uint16_t floorreqid; |
| 147 | enum bfcp_priority priority; |
| 148 | struct bfcp_reqstatus reqstatus; |
| 149 | struct bfcp_errcode errcode; |
| 150 | char *errinfo; |
| 151 | char *partprovinfo; |
| 152 | char *statusinfo; |
| 153 | struct bfcp_supattr supattr; |
| 154 | struct bfcp_supprim supprim; |
| 155 | char *userdname; |
| 156 | char *useruri; |
| 157 | uint16_t reqbyid; |
| 158 | } v; |
| 159 | }; |
| 160 | |
| 161 | /** BFCP unknown attributes */ |
| 162 | struct bfcp_unknown_attr { |
| 163 | uint8_t typev[16]; |
| 164 | size_t typec; |
| 165 | }; |
| 166 | |
| 167 | /** BFCP Message */ |
| 168 | struct bfcp_msg { |
| 169 | struct bfcp_unknown_attr uma; |
| 170 | struct sa src; |
| 171 | uint8_t ver; |
| 172 | unsigned r:1; |
| 173 | unsigned f:1; |
| 174 | enum bfcp_prim prim; |
| 175 | uint16_t len; |
| 176 | uint32_t confid; |
| 177 | uint16_t tid; |
| 178 | uint16_t userid; |
| 179 | struct list attrl; |
| 180 | }; |
| 181 | |
| 182 | struct tls; |
| 183 | struct bfcp_conn; |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * Defines the BFCP encode handler |
| 188 | * |
| 189 | * @param mb Mbuf to encode into |
| 190 | * @param arg Handler argument |
| 191 | * |
| 192 | * @return 0 if success, otherwise errorcode |
| 193 | */ |
| 194 | typedef int (bfcp_encode_h)(struct mbuf *mb, void *arg); |
| 195 | |
| 196 | /** BFCP Encode */ |
| 197 | struct bfcp_encode { |
| 198 | bfcp_encode_h *ench; |
| 199 | void *arg; |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | /** |
| 204 | * Defines the BFCP attribute handler |
| 205 | * |
| 206 | * @param attr BFCP attribute |
| 207 | * @param arg Handler argument |
| 208 | * |
| 209 | * @return True to stop processing, false to continue |
| 210 | */ |
| 211 | typedef bool (bfcp_attr_h)(const struct bfcp_attr *attr, void *arg); |
| 212 | |
| 213 | |
| 214 | /** |
| 215 | * Defines the BFCP receive handler |
| 216 | * |
| 217 | * @param msg BFCP message |
| 218 | * @param arg Handler argument |
| 219 | */ |
| 220 | typedef void (bfcp_recv_h)(const struct bfcp_msg *msg, void *arg); |
| 221 | |
| 222 | |
| 223 | /** |
| 224 | * Defines the BFCP response handler |
| 225 | * |
| 226 | * @param err Error code |
| 227 | * @param msg BFCP message |
| 228 | * @param arg Handler argument |
| 229 | */ |
| 230 | typedef void (bfcp_resp_h)(int err, const struct bfcp_msg *msg, void *arg); |
| 231 | |
| 232 | |
| 233 | /* attr */ |
| 234 | int bfcp_attrs_vencode(struct mbuf *mb, unsigned attrc, va_list *ap); |
| 235 | int bfcp_attrs_encode(struct mbuf *mb, unsigned attrc, ...); |
| 236 | struct bfcp_attr *bfcp_attr_subattr(const struct bfcp_attr *attr, |
| 237 | enum bfcp_attrib type); |
| 238 | struct bfcp_attr *bfcp_attr_subattr_apply(const struct bfcp_attr *attr, |
| 239 | bfcp_attr_h *h, void *arg); |
| 240 | int bfcp_attr_print(struct re_printf *pf, const struct bfcp_attr *attr); |
| 241 | const char *bfcp_attr_name(enum bfcp_attrib type); |
| 242 | const char *bfcp_reqstatus_name(enum bfcp_reqstat status); |
| 243 | const char *bfcp_errcode_name(enum bfcp_err code); |
| 244 | |
| 245 | |
| 246 | /* msg */ |
| 247 | int bfcp_msg_vencode(struct mbuf *mb, uint8_t ver, bool r, enum bfcp_prim prim, |
| 248 | uint32_t confid, uint16_t tid, uint16_t userid, |
| 249 | unsigned attrc, va_list *ap); |
| 250 | int bfcp_msg_encode(struct mbuf *mb, uint8_t ver, bool r, enum bfcp_prim prim, |
| 251 | uint32_t confid, uint16_t tid, uint16_t userid, |
| 252 | unsigned attrc, ...); |
| 253 | int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb); |
| 254 | struct bfcp_attr *bfcp_msg_attr(const struct bfcp_msg *msg, |
| 255 | enum bfcp_attrib type); |
| 256 | struct bfcp_attr *bfcp_msg_attr_apply(const struct bfcp_msg *msg, |
| 257 | bfcp_attr_h *h, void *arg); |
| 258 | int bfcp_msg_print(struct re_printf *pf, const struct bfcp_msg *msg); |
| 259 | const char *bfcp_prim_name(enum bfcp_prim prim); |
| 260 | |
| 261 | |
| 262 | /* conn */ |
| 263 | int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr, |
| 264 | struct tls *tls, bfcp_recv_h *recvh, void *arg); |
| 265 | void *bfcp_sock(const struct bfcp_conn *bc); |
| 266 | |
| 267 | |
| 268 | /* request */ |
| 269 | int bfcp_request(struct bfcp_conn *bc, const struct sa *dst, uint8_t ver, |
| 270 | enum bfcp_prim prim, uint32_t confid, uint16_t userid, |
| 271 | bfcp_resp_h *resph, void *arg, unsigned attrc, ...); |
| 272 | |
| 273 | |
| 274 | /* notify */ |
| 275 | int bfcp_notify(struct bfcp_conn *bc, const struct sa *dst, uint8_t ver, |
| 276 | enum bfcp_prim prim, uint32_t confid, uint16_t userid, |
| 277 | unsigned attrc, ...); |
| 278 | |
| 279 | |
| 280 | /* reply */ |
| 281 | int bfcp_reply(struct bfcp_conn *bc, const struct bfcp_msg *req, |
| 282 | enum bfcp_prim prim, unsigned attrc, ...); |
| 283 | int bfcp_edreply(struct bfcp_conn *bc, const struct bfcp_msg *req, |
| 284 | enum bfcp_err code, const uint8_t *details, size_t len); |
| 285 | int bfcp_ereply(struct bfcp_conn *bc, const struct bfcp_msg *req, |
| 286 | enum bfcp_err code); |