1 /** 2 * @file re_ice.h Interface to Interactive Connectivity Establishment (ICE) 3 * 4 * Copyright (C) 2010 Creytiv.com 5 */ 6 7 8 /** ICE mode */ 9 enum ice_mode { 10 ICE_MODE_FULL, 11 ICE_MODE_LITE 12 }; 13 14 /** ICE Role */ 15 enum ice_role { 16 ICE_ROLE_UNKNOWN = 0, 17 ICE_ROLE_CONTROLLING, 18 ICE_ROLE_CONTROLLED 19 }; 20 21 /** ICE Component ID */ 22 enum ice_compid { 23 ICE_COMPID_RTP = 1, 24 ICE_COMPID_RTCP = 2 25 }; 26 27 /** ICE Nomination */ 28 enum ice_nomination { 29 ICE_NOMINATION_REGULAR = 0, 30 ICE_NOMINATION_AGGRESSIVE 31 }; 32 33 /** ICE Candidate type */ 34 enum ice_cand_type { 35 ICE_CAND_TYPE_HOST, /**< Host candidate */ 36 ICE_CAND_TYPE_SRFLX, /**< Server Reflexive candidate */ 37 ICE_CAND_TYPE_PRFLX, /**< Peer Reflexive candidate */ 38 ICE_CAND_TYPE_RELAY /**< Relayed candidate */ 39 }; 40 41 /** ICE TCP protocol type */ 42 enum ice_tcptype { 43 ICE_TCP_ACTIVE, /**< Active TCP client */ 44 ICE_TCP_PASSIVE, /**< Passive TCP server */ 45 ICE_TCP_SO /**< Simultaneous-open TCP client/server */ 46 }; 47 48 /** Candidate pair states */ 49 enum ice_candpair_state { 50 ICE_CANDPAIR_FROZEN = 0, /**< Frozen state (default) */ 51 ICE_CANDPAIR_WAITING, /**< Waiting to become highest on list */ 52 ICE_CANDPAIR_INPROGRESS, /**< In-Progress state;transac. in progress */ 53 ICE_CANDPAIR_SUCCEEDED, /**< Succeeded state; successful result */ 54 ICE_CANDPAIR_FAILED /**< Failed state; check failed */ 55 }; 56 57 struct ice; 58 struct ice_cand; 59 struct icem; 60 struct turnc; 61 62 /** ICE Configuration */ 63 struct ice_conf { 64 enum ice_nomination nom; /**< Nomination algorithm */ 65 uint32_t rto; /**< STUN Retransmission TimeOut */ 66 uint32_t rc; /**< STUN Retransmission Count */ 67 bool debug; /**< Enable ICE debugging */ 68 }; 69 70 typedef void (ice_connchk_h)(int err, bool update, void *arg); 71 72 73 /* ICE Media */ 74 int icem_alloc(struct icem **icemp, enum ice_mode mode, 75 enum ice_role role, int proto, int layer, 76 uint64_t tiebrk, const char *lufrag, const char *lpwd, 77 ice_connchk_h *chkh, void *arg); 78 struct ice_conf *icem_conf(struct icem *icem); 79 enum ice_role icem_local_role(const struct icem *icem); 80 void icem_set_conf(struct icem *icem, const struct ice_conf *conf); 81 void icem_set_role(struct icem *icem, enum ice_role role); 82 void icem_set_name(struct icem *icem, const char *name); 83 int icem_comp_add(struct icem *icem, unsigned compid, void *sock); 84 int icem_cand_add(struct icem *icem, unsigned compid, uint16_t lprio, 85 const char *ifname, const struct sa *addr); 86 87 int icem_lite_set_default_candidates(struct icem *icem); 88 bool icem_verify_support(struct icem *icem, unsigned compid, 89 const struct sa *raddr); 90 int icem_conncheck_start(struct icem *icem); 91 void icem_conncheck_stop(struct icem *icem, int err); 92 int icem_add_chan(struct icem *icem, unsigned compid, const struct sa *raddr); 93 bool icem_mismatch(const struct icem *icem); 94 void icem_update(struct icem *icem); 95 int ice_sdp_decode(struct icem *ice, const char *name, const char *value); 96 int icem_sdp_decode(struct icem *icem, const char *name, const char *value); 97 int icem_debug(struct re_printf *pf, const struct icem *icem); 98 struct list *icem_lcandl(const struct icem *icem); 99 struct list *icem_rcandl(const struct icem *icem); 100 struct list *icem_checkl(const struct icem *icem); 101 struct list *icem_validl(const struct icem *icem); 102 const struct sa *icem_cand_default(struct icem *icem, unsigned compid); 103 const struct sa *icem_selected_laddr(const struct icem *icem, unsigned compid); 104 const struct ice_cand *icem_selected_lcand(const struct icem *icem, 105 unsigned compid); 106 const struct ice_cand *icem_selected_rcand(const struct icem *icem, 107 unsigned compid); 108 void ice_candpair_set_states(struct icem *icem); 109 void icem_cand_redund_elim(struct icem *icem); 110 int icem_comps_set_default_cand(struct icem *icem); 111 struct stun *icem_stun(struct icem *icem); 112 int icem_set_turn_client(struct icem *icem, unsigned compid, 113 struct turnc *turnc); 114 115 116 bool ice_remotecands_avail(const struct icem *icem); 117 int ice_cand_encode(struct re_printf *pf, const struct ice_cand *cand); 118 int ice_remotecands_encode(struct re_printf *pf, const struct icem *icem); 119 struct ice_cand *icem_cand_find(const struct list *lst, unsigned compid, 120 const struct sa *addr); 121 int icem_lcand_add(struct icem *icem, struct ice_cand *base, 122 enum ice_cand_type type, 123 const struct sa *addr); 124 struct ice_cand *icem_lcand_base(struct ice_cand *lcand); 125 const struct sa *icem_lcand_addr(const struct ice_cand *cand); 126 enum ice_cand_type icem_cand_type(const struct ice_cand *cand); 127 128 129 extern const char ice_attr_cand[]; 130 extern const char ice_attr_lite[]; 131 extern const char ice_attr_mismatch[]; 132 extern const char ice_attr_pwd[]; 133 extern const char ice_attr_remote_cand[]; 134 extern const char ice_attr_ufrag[]; 135 136 137 const char *ice_cand_type2name(enum ice_cand_type type); 138 enum ice_cand_type ice_cand_name2type(const char *name); 139 const char *ice_role2name(enum ice_role role); 140 const char *ice_candpair_state2name(enum ice_candpair_state st); 141 142 143 uint32_t ice_cand_calc_prio(enum ice_cand_type type, uint16_t local, 144 unsigned compid); 145 146 147 /** Defines an SDP candidate attribute */ 148 struct ice_cand_attr { 149 char foundation[32]; /**< Foundation string */ 150 unsigned compid; /**< Component ID (1-256) */ 151 int proto; /**< Transport protocol */ 152 uint32_t prio; /**< Priority of this candidate */ 153 struct sa addr; /**< Transport address */ 154 enum ice_cand_type type; /**< Candidate type */ 155 struct sa rel_addr; /**< Related transport address (optional) */ 156 enum ice_tcptype tcptype; /**< TCP candidate type (TCP-only) */ 157 }; 158 159 int ice_cand_attr_encode(struct re_printf *pf, 160 const struct ice_cand_attr *cand); 161 int ice_cand_attr_decode(struct ice_cand_attr *cand, const char *val); 162