From 631fffee8a28b1bec5ed1f1d26a20e0135967f99 Mon Sep 17 00:00:00 2001 From: Mamadou DIOP Date: Mon, 17 Aug 2015 01:56:35 +0200 Subject: - --- tinyBFCP/include/tinybfcp/tbfcp_attr.h | 98 ++++++++++++++ tinyBFCP/include/tinybfcp/tbfcp_pkt.h | 107 +++++++++++++++ tinyBFCP/include/tinybfcp/tbfcp_session.h | 72 +++++++++++ tinyBFCP/include/tinybfcp/tbfcp_types.h | 207 ++++++++++++++++++++++++++++++ tinyBFCP/include/tinybfcp/tbfcp_utils.h | 43 +++++++ 5 files changed, 527 insertions(+) create mode 100644 tinyBFCP/include/tinybfcp/tbfcp_attr.h create mode 100644 tinyBFCP/include/tinybfcp/tbfcp_pkt.h create mode 100644 tinyBFCP/include/tinybfcp/tbfcp_session.h create mode 100644 tinyBFCP/include/tinybfcp/tbfcp_types.h create mode 100644 tinyBFCP/include/tinybfcp/tbfcp_utils.h (limited to 'tinyBFCP/include/tinybfcp') diff --git a/tinyBFCP/include/tinybfcp/tbfcp_attr.h b/tinyBFCP/include/tinybfcp/tbfcp_attr.h new file mode 100644 index 0000000..c83f805 --- /dev/null +++ b/tinyBFCP/include/tinybfcp/tbfcp_attr.h @@ -0,0 +1,98 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TBFCP_ATTR_H +#define TBFCP_ATTR_H + +#include "tinybfcp_config.h" +#include "tinybfcp/tbfcp_types.h" + +#include "tsk_object.h" +#include "tsk_list.h" + +TBFCP_BEGIN_DECLS + +#if !defined(TBFCP_ATTR_HDR_SIZE_IN_OCTETS) +# define TBFCP_ATTR_HDR_SIZE_IN_OCTETS 2 /* 2 Octets: Type(7bits),M(1bit),Length(8bits) */ +#endif /* TBFCP_ATTR_HDR_SIZE_IN_OCTETS */ + +// RFC4582 - 5.2. Attribute Format +typedef struct tbfcp_attr_hdr_xs { + enum tbfcp_attribute_type_e type; // 7bits + unsigned M:1; // Mandatory // 1bit + uint8_t length; // 8bits excluding any padding defined for specific attributes +} tbfcp_attr_hdr_xt; + +typedef struct tbfcp_attr_s { + TSK_DECLARE_OBJECT; + struct tbfcp_attr_s* pc_base; + struct tbfcp_attr_hdr_xs hdr; + enum tbfcp_attribute_format_e format; +} tbfcp_attr_t; +#define TBFCP_DECLARE_ATTR struct tbfcp_attr_s __base__ +#define TBFCP_ATTR(p_self) ((struct tbfcp_attr_s*)(p_self)) +typedef tsk_list_t tbfcp_attrs_L_t; +TINYBFCP_API int tbfcp_attr_get_size_in_octetunits_without_padding(const struct tbfcp_attr_s* pc_self, tsk_size_t* p_size); +TINYBFCP_API int tbfcp_attr_get_size_in_octetunits_with_padding(const struct tbfcp_attr_s* pc_self, tsk_size_t* p_size); +TINYBFCP_API int tbfcp_attr_write_without_padding(const struct tbfcp_attr_s* pc_self, uint8_t* p_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_written); +TINYBFCP_API int tbfcp_attr_write_with_padding(const struct tbfcp_attr_s* pc_self, uint8_t* p_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_written); +TINYBFCP_API int tbfcp_attr_read(const uint8_t* pc_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_consumed_octets, struct tbfcp_attr_s** pp_attr); + +typedef struct tbfcp_attr_unsigned16_s { + TBFCP_DECLARE_ATTR; + uint16_t Unsigned16; +} tbfcp_attr_unsigned16_t; +#define TBFCP_ATTR_UNSIGNED16(p_self) ((struct tbfcp_attr_unsigned16_s*)(p_self)) +TINYBFCP_API int tbfcp_attr_unsigned16_create(enum tbfcp_attribute_type_e type, unsigned M, uint16_t Unsigned16, struct tbfcp_attr_unsigned16_s** pp_self); + +typedef struct tbfcp_attr_octetstring16_s { + TBFCP_DECLARE_ATTR; + uint8_t OctetString16[2]; +} tbfcp_attr_octetstring16_t; +#define TBFCP_ATTR_OCTETSTRING16(p_self) ((struct tbfcp_attr_octetstring16_s*)(p_self)) +TINYBFCP_API int tbfcp_attr_octetstring16_create(enum tbfcp_attribute_type_e type, unsigned M, uint8_t OctetString16[2], struct tbfcp_attr_octetstring16_s** pp_self); + +typedef struct tbfcp_attr_octetstring_s { + TBFCP_DECLARE_ATTR; + uint8_t *OctetString; + uint8_t OctetStringLength; // Length in octet excluding any paddding +} tbfcp_attr_octetstring_t; +#define TBFCP_ATTR_OCTETSTRING(p_self) ((struct tbfcp_attr_octetstring_s*)(p_self)) +TINYBFCP_API int tbfcp_attr_octetstring_create(enum tbfcp_attribute_type_e type, unsigned M, const uint8_t *OctetString, uint8_t OctetStringLength, struct tbfcp_attr_octetstring_s** pp_self); + +typedef struct tbfcp_attr_grouped_s { + TBFCP_DECLARE_ATTR; + union { + uint16_t BeneficiaryID; // 5.2.14. BENEFICIARY-INFORMATION + uint16_t FloorRequestID; // 5.2.15. FLOOR-REQUEST-INFORMATION && 5.2.18. OVERALL-REQUEST-STATUS + uint16_t RequestedbyID; // 5.2.16. REQUESTED-BY-INFORMATION + uint16_t FloorID; // 5.2.17. FLOOR-REQUEST-STATUS + } extra_hdr; + uint8_t extra_hdr_size_in_octets; + tbfcp_attrs_L_t *p_list_attrs; +} tbfcp_attr_grouped_t; +#define TBFCP_ATTR_GROUPED(p_self) ((struct tbfcp_attr_grouped_s*)(p_self)) +TINYBFCP_API int tbfcp_attr_grouped_create(enum tbfcp_attribute_type_e type, unsigned M, struct tbfcp_attr_grouped_s** pp_self); +TINYBFCP_API int tbfcp_attr_grouped_create_u16(enum tbfcp_attribute_type_e type, unsigned M, uint16_t extra_hdr_u16_val, struct tbfcp_attr_grouped_s** pp_self); +TINYBFCP_API int tbfcp_attr_grouped_add_attr(struct tbfcp_attr_grouped_s* p_self, struct tbfcp_attr_s** p_attr); +TINYBFCP_API int tbfcp_attr_grouped_find_at(const struct tbfcp_attr_grouped_s* pc_self, enum tbfcp_attribute_format_e e_format, tsk_size_t u_index, const struct tbfcp_attr_s** ppc_attr); + +TBFCP_END_DECLS + +#endif /* TBFCP_ATTR_H */ + diff --git a/tinyBFCP/include/tinybfcp/tbfcp_pkt.h b/tinyBFCP/include/tinybfcp/tbfcp_pkt.h new file mode 100644 index 0000000..92353cc --- /dev/null +++ b/tinyBFCP/include/tinybfcp/tbfcp_pkt.h @@ -0,0 +1,107 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TBFCP_PKT_H +#define TBFCP_PKT_H + +#include "tinybfcp_config.h" +#include "tinybfcp/tbfcp_types.h" +#include "tinybfcp/tbfcp_attr.h" + +#include "tsk_object.h" +#include "tsk_list.h" + +TBFCP_BEGIN_DECLS + +#if !defined(TBFCP_PKT_HDR_SIZE_IN_OCTETS) +# define TBFCP_PKT_HDR_SIZE_IN_OCTETS 12 +#endif /* TBFCP_PKT_HDR_SIZE_IN_OCTETS */ + +typedef tsk_list_t tbfcp_pkts_L_t; +typedef struct tbfcp_pkt_s { + TSK_DECLARE_OBJECT; + + struct { + // rfc4582 - 5.1. COMMON-HEADER Format + unsigned ver:3; + unsigned reserved:5; + enum tbfcp_primitive_e primitive; // 8bits + uint16_t pay_len; // 16bits: the length of the message in 4-octet units, excluding the common header + uint32_t conf_id; + uint16_t transac_id; + uint16_t user_id; + } hdr; + int (*f_add_attr)(struct tbfcp_pkt_s* p_self, struct tbfcp_attr_s** pp_attr); + tbfcp_attrs_L_t *p_list_attrs; +} +tbfcp_pkt_t; +#define TBFCP_DECLARE_PKT struct tbfcp_pkt_s __base__ +#define TBFCP_PKT(p_self) ((struct tbfcp_pkt_s*)(p_self)) +TINYBFCP_API int tbfcp_pkt_add_attr(struct tbfcp_pkt_s* p_self, struct tbfcp_attr_s** pp_attr); +TINYBFCP_API int tbfcp_pkt_create_empty(enum tbfcp_primitive_e primitive, struct tbfcp_pkt_s** pp_self); +TINYBFCP_API int tbfcp_pkt_create(enum tbfcp_primitive_e primitive, uint32_t conf_id, uint16_t transac_id, uint16_t user_id, struct tbfcp_pkt_s** pp_self); +TINYBFCP_API int tbfcp_pkt_get_size_in_octetunits_without_padding(const struct tbfcp_pkt_s* pc_self, tsk_size_t* p_size); +TINYBFCP_API int tbfcp_pkt_get_size_in_octetunits_with_padding(const struct tbfcp_pkt_s* pc_self, tsk_size_t* p_size); +TINYBFCP_API int tbfcp_pkt_write_with_padding(const struct tbfcp_pkt_s* pc_self, uint8_t* p_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_written); +TINYBFCP_API int tbfcp_pkt_is_complete(const uint8_t* pc_buff_ptr, tsk_size_t n_buff_size, tsk_bool_t *pb_is_complete); +TINYBFCP_API int tbfcp_pkt_read(const uint8_t* pc_buff_ptr, tsk_size_t n_buff_size, struct tbfcp_pkt_s** pp_pkt); +TINYBFCP_API int tbfcp_pkt_attr_find_at(const struct tbfcp_pkt_s* pc_self, enum tbfcp_attribute_format_e e_format, tsk_size_t u_index, const struct tbfcp_attr_s** ppc_attr); +#define tbfcp_pkt_attr_find_first(pc_self, e_format, ppc_attr) tbfcp_pkt_attr_find_at(pc_self, e_format, 0, ppc_attr) + +/***** rfc4582 - 5.3.1. FloorRequest *****/ +#define tbfcp_pkt_create_FloorRequest(conf_id, transac_id, user_id, pp_self) tbfcp_pkt_create(tbfcp_primitive_FloorRequest, (conf_id), (transac_id), (user_id), (pp_self)) +#define tbfcp_pkt_create_empty_FloorRequest(p_self) tbfcp_pkt_create_empty(TBFCP_PKT(p_self), tbfcp_primitive_FloorRequest) +TINYBFCP_API int tbfcp_pkt_create_FloorRequest_2(uint32_t conf_id, uint16_t transac_id, uint16_t user_id, uint16_t floor_id, struct tbfcp_pkt_s** pp_self); + +/***** rfc4582 - 5.3.2. FloorRelease *****/ +#define tbfcp_pkt_create_FloorRelease(conf_id, transac_id, user_id, pp_self) tbfcp_pkt_create(tbfcp_primitive_FloorRelease, (conf_id), (transac_id), (user_id), (pp_self)) +#define tbfcp_pkt_create_empty_FloorRelease(p_self) tbfcp_pkt_create_empty(TBFCP_PKT(p_self), tbfcp_primitive_FloorRelease) +TINYBFCP_API int tbfcp_pkt_create_FloorRelease_2(uint32_t conf_id, uint16_t transac_id, uint16_t user_id, uint16_t floor_req_id, struct tbfcp_pkt_s** pp_self); + + +/**** rfc4582 - 5.3.4. FloorRequestStatus *****/ +#define tbfcp_pkt_create_FloorRequestStatus(conf_id, transac_id, user_id, pp_self) tbfcp_pkt_create(tbfcp_primitive_FloorRequestStatus, (conf_id), (transac_id), (user_id), (pp_self)) +#define tbfcp_pkt_create_empty_FloorRequestStatus(p_self) tbfcp_pkt_create_empty(TBFCP_PKT(p_self), tbfcp_primitive_FloorRequestStatus) +TINYBFCP_API int tbfcp_pkt_create_FloorRequestStatus_2(uint32_t conf_id, uint16_t transac_id, uint16_t user_id, uint16_t floor_req_id, struct tbfcp_pkt_s** pp_self); + +/**** rfc4582 - 5.3.11. Hello ***/ +#define tbfcp_pkt_create_Hello(conf_id, transac_id, user_id, pp_self) tbfcp_pkt_create(tbfcp_primitive_Hello, (conf_id), (transac_id), (user_id), (pp_self)) +#define tbfcp_pkt_create_empty_Hello(p_self) tbfcp_pkt_create_empty(TBFCP_PKT(p_self), tbfcp_primitive_Hello) + +/**** 5.3.12. HelloAck ***/ +#define tbfcp_pkt_create_HelloAck(conf_id, transac_id, user_id, pp_self) tbfcp_pkt_create(tbfcp_primitive_HelloAck, (conf_id), (transac_id), (user_id), (pp_self)) +#define tbfcp_pkt_create_empty_HelloAck(p_self) tbfcp_pkt_create_empty(TBFCP_PKT(p_self), tbfcp_primitive_HelloAck) +TINYBFCP_API int tbfcp_pkt_create_HelloAck_2(uint32_t conf_id, uint16_t transac_id, uint16_t user_id, struct tbfcp_pkt_s** pp_self); + +#if 0 +// rfc4582 - 5.3.1. FloorRequest +typedef struct tbfcp_pkt_FloorRequest_s { + TBFCP_DECLARE_PKT; + struct tbfcp_attr_unsigned16_s* p_floor_id; // First [FLOOR-ID]. Others will be in "p_list_exts". + struct tbfcp_attr_unsigned16_s* p_beneficiary_id; // [BENEFICIARY-ID] + struct tbfcp_attr_octetstring_s* p_participant_provided_info; // [PARTICIPANT-PROVIDED-INFO] + struct tbfcp_attr_octetstring16_s* p_priority; // [PRIORITY] +} tbfcp_pkt_FloorRequest_t; +TINYBFCP_API int tbfcp_pkt_FloorRequest_create_empty(struct tbfcp_pkt_FloorRequest_s** pp_self); +TINYBFCP_API int tbfcp_pkt_FloorRequest_create(uint32_t conf_id, uint16_t transac_id, uint16_t user_id, uint16_t floor_id, struct tbfcp_pkt_FloorRequest_s** pp_self); +#endif + +TBFCP_END_DECLS + +#endif /* TBFCP_PKT_H */ + diff --git a/tinyBFCP/include/tinybfcp/tbfcp_session.h b/tinyBFCP/include/tinybfcp/tbfcp_session.h new file mode 100644 index 0000000..82e57f6 --- /dev/null +++ b/tinyBFCP/include/tinybfcp/tbfcp_session.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TBFCP_SESSION_H +#define TBFCP_SESSION_H + +#include "tinybfcp_config.h" +#include "tinybfcp/tbfcp_types.h" + +#include "tinynet.h" + +TBFCP_BEGIN_DECLS + +struct tbfcp_session_s; +struct tbfcp_pkt_s; + +typedef enum tbfcp_session_event_type_e +{ + tbfcp_session_event_type_inf_inc_msg, + tbfcp_session_event_type_err_send_timedout +} +tbfcp_session_event_type_t; + +typedef struct tbfcp_session_event_xs { + enum tbfcp_session_event_type_e e_type; + const struct tbfcp_pkt_s* pc_pkt; + const void* pc_usr_data; +} tbfcp_session_event_xt; + +typedef int (*tbfcp_session_callback_f)(const struct tbfcp_session_event_xs *e); + +TINYBFCP_API int tbfcp_session_create(enum tnet_socket_type_e e_socket_type, const char* pc_local_ip, struct tbfcp_session_s** pp_self); +TINYBFCP_API int tbfcp_session_create_2(struct tnet_ice_ctx_s* p_ice_ctx, struct tbfcp_session_s** pp_self); +TINYBFCP_API int tbfcp_session_set_callback(struct tbfcp_session_s* p_self, tbfcp_session_callback_f f_fun, const void* pc_usr_data); +TINYBFCP_API int tbfcp_session_set_ice_ctx(struct tbfcp_session_s* p_self, struct tnet_ice_ctx_s* p_ice_ctx); +TINYBFCP_API int tbfcp_session_prepare(struct tbfcp_session_s* p_self); +TINYBFCP_API int tbfcp_session_start(struct tbfcp_session_s* p_self); +TINYBFCP_API int tbfcp_session_pause(struct tbfcp_session_s* p_self); +TINYBFCP_API int tbfcp_session_stop(struct tbfcp_session_s* p_self); +TINYBFCP_API int tbfcp_session_set_natt_ctx(struct tbfcp_session_s* p_self, struct tnet_nat_ctx_s* p_natt_ctx); +TINYBFCP_API int tbfcp_session_set_remote_address(struct tbfcp_session_s* p_self, const char* pc_ip, tnet_port_t u_port); +TINYBFCP_API int tbfcp_session_set_remote_role(struct tbfcp_session_s* p_self, enum tbfcp_role_e e_role_remote); +TINYBFCP_API int tbfcp_session_set_remote_setup(struct tbfcp_session_s* p_self, enum tbfcp_setup_e e_setup_remote); +TINYBFCP_API int tbfcp_session_set_conf_ids(struct tbfcp_session_s* p_self, uint32_t u_conf_id, uint16_t u_user_id, uint16_t u_floor_id); +TINYBFCP_API int tbfcp_session_get_profile(const struct tbfcp_session_s* pc_self, const char** ppc_profile); +TINYBFCP_API int tbfcp_session_get_local_role(const struct tbfcp_session_s* pc_self, enum tbfcp_role_e *pe_role_local); +TINYBFCP_API int tbfcp_session_get_local_setup(const struct tbfcp_session_s* pc_self, enum tbfcp_setup_e *pe_setup_local); +TINYBFCP_API int tbfcp_session_get_local_address(const struct tbfcp_session_s* pc_self, const char** ppc_ip, tnet_port_t *pu_port); +TINYBFCP_API int tbfcp_session_create_pkt_Hello(struct tbfcp_session_s* p_self, struct tbfcp_pkt_s** pp_pkt); +TINYBFCP_API int tbfcp_session_create_pkt_FloorRequest(struct tbfcp_session_s* p_self, struct tbfcp_pkt_s** pp_pkt); +TINYBFCP_API int tbfcp_session_create_pkt_FloorRelease(struct tbfcp_session_s* p_self, struct tbfcp_pkt_s** pp_pkt); +TINYBFCP_API int tbfcp_session_send_pkt(struct tbfcp_session_s* p_self, const struct tbfcp_pkt_s* pc_pkt); + +TBFCP_END_DECLS + +#endif /* TBFCP_SESSION_H */ + diff --git a/tinyBFCP/include/tinybfcp/tbfcp_types.h b/tinyBFCP/include/tinybfcp/tbfcp_types.h new file mode 100644 index 0000000..561d7be --- /dev/null +++ b/tinyBFCP/include/tinybfcp/tbfcp_types.h @@ -0,0 +1,207 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TBFCP_TYPES_H +#define TBFCP_TYPES_H + +#include "tinybfcp_config.h" + +TBFCP_BEGIN_DECLS + +#if !defined(kBfcpFieldMYes) +# define kBfcpFieldMYes 1 +#endif /* kBfcpFieldMYes */ +#if !defined(kBfcpFieldMNo) +# define kBfcpFieldMNo 0 +#endif /* kBfcpFieldMNo */ + +// draft-ietf-bfcpbis-rfc4582bis-11 - 8.3.3. Timer Values +#if !defined(kBfcpTimerT1) +# define kBfcpTimerT1 500 +#endif /* kBfcpTimerT1 */ +#if !defined(kBfcpTimerT2) +# define kBfcpTimerT2 10000 +#endif /* kBfcpTimerT1 */ +#if !defined(kBfcpTimerT1MaxTries) +# define kBfcpTimerT1MaxTries 4 // draft says #3 but we use #4 +#endif /* kBfcpTimerT1MaxTries */ +#if !defined(kBfcpTimerT1Max) +# define kBfcpTimerT1Max (kBfcpTimerT1 * kBfcpTimerT1MaxTries) +#endif /* kBfcpTimerT1 */ + +#if !defined(kBfcpTcpTimerReconnect) +# define kBfcpTcpTimerReconnect 5000 // Try to reconnect the TCP/TLS socket every 5seconds if unexpectedly disconnected +#endif /* kBfcpTcpTimerReconnect */ + +#if !defined(kBfcpTimerKeepAlive) +# define kBfcpTimerKeepAlive 30000 // Send Hello message every 30 seconds +#endif /* kBfcpTimerKeepAlive */ + + +// RFC4582 - 11.1. Registration of the 'TCP/BFCP' and 'TCP/TLS/BFCP' SDP 'proto' Values +#if !defined (kBfcpProfileTLS) +# define kBfcpProfileTLS "TCP/TLS/BFCP" +#endif /* kBfcpProfileTLS */ +#if !defined (kBfcpProfileTCP) +# define kBfcpProfileTCP "TCP/BFCP" +#endif /* kBfcpProfileTCP */ +// draft-ietf-bfcpbis-rfc4582bis-11 - 5.4. Registration of SDP 'proto' Values (11.1) +#if !defined (kBfcpProfileUDP) +# define kBfcpProfileUDP "UDP/BFCP" +#endif /* kBfcpProfileUDP */ +#if !defined (kBfcpProfileDTLS) +# define kBfcpProfileDTLS "UDP/TLS/BFCP" +#endif /* kBfcpProfileDTLS */ + +#if !defined(kBfcpTransportDefault) +# define kBfcpTransportDefault tnet_socket_type_udp_ipv4 +#endif /* kBfcpTransportDefault */ + +#if !defined(kBfcpTransportFriendlyName) +# define kBfcpTransportFriendlyName "BFCP Session" +#endif /* kBfcpTransportFriendlyName */ + +#if !defined(kBfcpBuffMinPad) +# define kBfcpBuffMinPad 40 // to make the buffer kasher +#endif /* kBfcpBuffMinPad */ + + +// rfc4583 - 4. Floor Control Server Determination +#if !defined(kBfcpRoleC) +# define kBfcpRoleC "c-only" +#endif /* kBfcpRoleC */ +#if !defined(kBfcpRoleS) +# define kBfcpRoleS "s-only" +#endif /* kBfcpRoleS */ +#if !defined(kBfcpRoleCS) +# define kBfcpRoleCS "c-s" +#endif /* kBfcpRoleCS */ +#if !defined(kBfcpRoleDefault) +# define kBfcpRoleDefault tbfcp_role_c_only // For know the stack works in client mode only +#endif /* kBfcpRoleDefault */ +typedef enum tbfcp_role_e { + tbfcp_role_c_only = (1 << 0), + tbfcp_role_s_only = (1 << 1), + tbfcp_role_c_s = (tbfcp_role_c_only | tbfcp_role_s_only) +} tbfcp_role_t; + +typedef enum tbfcp_setup_e { + tbfcp_setup_active = (1 << 0), + tbfcp_setup_passive = (1 << 1), + tbfcp_setup_actpass = (tbfcp_setup_active | tbfcp_setup_passive), +} tbfcp_setup_t; +#if !defined(kBfcpSetupDefault) +# define kBfcpSetupDefault tbfcp_setup_actpass +#endif /* kBfcpSetupDefault */ +#if !defined(kBfcpSetupActPass) +# define kBfcpSetupActPass "actpass" +#endif /* kBfcpSetupActPass */ +#if !defined(kBfcpSetupActive) +# define kBfcpSetupActive "active" +#endif /* kBfcpSetupActive */ +#if !defined(kBfcpSetupPassive) +# define kBfcpSetupPassive "passive" +#endif /* kBfcpSetupPassive */ + +// RFC4582 - 5.1. COMMON-HEADER Format +typedef enum tbfcp_primitive_e { + tbfcp_primitive_FloorRequest = 1, // | P -> S | + tbfcp_primitive_FloorRelease = 2, // | P -> S | + tbfcp_primitive_FloorRequestQuery = 3, // | P -> S ; Ch -> S | + tbfcp_primitive_FloorRequestStatus = 4, // | P <- S ; Ch <- S | + tbfcp_primitive_UserQuery = 5, // | P -> S ; Ch -> S | + tbfcp_primitive_UserStatus = 6, // | P <- S ; Ch <- S | + tbfcp_primitive_FloorQuery = 7, // | P -> S ; Ch -> S | + tbfcp_primitive_FloorStatus = 8, // | P <- S ; Ch <- S | + tbfcp_primitive_ChairAction = 9, // | Ch -> S | + tbfcp_primitive_ChairActionAck = 10, // | Ch <- S | + tbfcp_primitive_Hello = 11, // | P -> S ; Ch -> S | + tbfcp_primitive_HelloAck = 12, // | P <- S ; Ch <- S | + tbfcp_primitive_Error = 13, // | P <- S ; Ch <- S + //!\ Update tbfcp_pkt_create_HelloAck_2() if an entry is added or remove +} tbfcp_primitive_t; + +// RFC4582 - 5.2. Attribute Format +typedef enum tbfcp_attribute_type_e { + tbfcp_attribute_type_BENEFICIARY_ID = 1, // | Unsigned16 | + tbfcp_attribute_type_FLOOR_ID = 2, // | Unsigned16 | + tbfcp_attribute_type_FLOOR_REQUEST_ID = 3, // | Unsigned16 | + tbfcp_attribute_type_PRIORITY = 4, // | OctetString16 | + tbfcp_attribute_type_REQUEST_STATUS = 5, // | OctetString16 | + tbfcp_attribute_type_ERROR_CODE = 6, // | OctetString | + tbfcp_attribute_type_ERROR_INFO = 7, // | OctetString | + tbfcp_attribute_type_PARTICIPANT_PROVIDED_INFO = 8, // | OctetString | + tbfcp_attribute_type_STATUS_INFO = 9, // | OctetString | + tbfcp_attribute_type_SUPPORTED_ATTRIBUTES = 10, // | OctetString | + tbfcp_attribute_type_SUPPORTED_PRIMITIVES = 11, // | OctetString | + tbfcp_attribute_type_USER_DISPLAY_NAME = 12, // | OctetString | + tbfcp_attribute_type_USER_URI = 13, // | OctetString | + tbfcp_attribute_type_BENEFICIARY_INFORMATION = 14, // | Grouped | + tbfcp_attribute_type_FLOOR_REQUEST_INFORMATION = 15, // | Grouped | + tbfcp_attribute_type_REQUESTED_BY_INFORMATION = 16, // | Grouped | + tbfcp_attribute_type_FLOOR_REQUEST_STATUS = 17, // | Grouped | + tbfcp_attribute_type_OVERALL_REQUEST_STATUS = 18, // | Grouped + //!\ Update tbfcp_pkt_create_HelloAck_2() if an entry is added or remove +} tbfcp_attribute_type_t; + +// RFC4582 - 5.2. Attribute Format +typedef enum tbfcp_attribute_format_e { + tbfcp_attribute_format_Unknown, + tbfcp_attribute_format_Unsigned16, + tbfcp_attribute_format_OctetString16, + tbfcp_attribute_format_OctetString, + tbfcp_attribute_format_Grouped, +} tbfcp_attribute_format_t; + +// RFC4582 - 5.2.4. PRIORITY +typedef enum tbfcp_prio_e { + tbfcp_prio_Lowest = 0, + tbfcp_prio_Low = 1, + tbfcp_prio_Normal = 2, + tbfcp_prio_High = 3, + tbfcp_prio_Highest = 4 +} tbfcp_prio_t; + +// RFC4582 - 5.2.5. REQUEST-STATUS +typedef enum tbfcp_reqstatus_e { + tbfcp_reqstatus_Pending = 1, + tbfcp_reqstatus_Accepted = 2, + tbfcp_reqstatus_Granted = 3, + tbfcp_reqstatus_Denied = 4, + tbfcp_reqstatus_Cancelled = 5, + tbfcp_reqstatus_Released = 6, + tbfcp_reqstatus_Revoked = 7 +} tbfcp_reqstatus_t; + +// RFC4582 - 5.2.6. ERROR-CODE +typedef enum tbfcp_err_code_e { + tbfcp_err_code_Conference_does_not_Exist = 1, + tbfcp_err_code_User_does_not_Exist = 2, + tbfcp_err_code_Unknown_Primitive = 3, + tbfcp_err_code_Unknown_Mandatory_Attribute = 4, + tbfcp_err_code_Unauthorized_Operation = 5, + tbfcp_err_code_Invalid_Floor_ID = 6, + tbfcp_err_code_Floor_Request_ID_Does_Not_Exist = 7, + tbfcp_err_code_You_have_Already_Reached_the_Maximum_Number_of_OngoingFloor_Requests_for_this_Floor = 9, + tbfcp_err_code_Use_TLS = 10, +} tbfcp_err_code_t; + +TBFCP_END_DECLS + +#endif /* TBFCP_TYPES_H */ + diff --git a/tinyBFCP/include/tinybfcp/tbfcp_utils.h b/tinyBFCP/include/tinybfcp/tbfcp_utils.h new file mode 100644 index 0000000..98c23c3 --- /dev/null +++ b/tinyBFCP/include/tinybfcp/tbfcp_utils.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TBFCP_UTILS_H +#define TBFCP_UTILS_H + +#include "tinybfcp_config.h" +#include "tinybfcp/tbfcp_types.h" + +#include "tsk_common.h" + +TBFCP_BEGIN_DECLS + +enum tnet_socket_type_e; + +TINYBFCP_API int tbfcp_utils_get_profile(enum tnet_socket_type_e e_socket_type, const char** ppc_profile); +TINYBFCP_API int tbfcp_utils_get_role(enum tbfcp_role_e e_role, const char** ppc_role); +TINYBFCP_API int tbfcp_utils_parse_role(const char* pc_role, enum tbfcp_role_e* pe_role); +TINYBFCP_API int tbfcp_utils_get_setup(enum tbfcp_role_e e_setup, const char** ppc_setup); +TINYBFCP_API int tbfcp_utils_parse_setup(const char* pc_setup, enum tbfcp_setup_e* pe_setup); +TINYBFCP_API int tbfcp_utils_is_role_acceptable(enum tbfcp_role_e e_role_local, enum tbfcp_role_e e_role_proposed, tsk_bool_t *pb_acceptable); +TINYBFCP_API int tbfcp_utils_is_setup_acceptable(enum tbfcp_setup_e e_setup_local, enum tbfcp_setup_e e_setup_proposed, tsk_bool_t *pb_acceptable); +TINYBFCP_API uint16_t tbfcp_utils_rand_u16(); + +TBFCP_END_DECLS + +#endif /* TBFCP_UTILS_H */ + -- cgit v1.1