blob: 6c72856134c76e68f9112b95545ef719fce4f8c9 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_ice.h Interface to Interactive Connectivity Establishment (ICE)
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7
8/** ICE mode */
9enum ice_mode {
10 ICE_MODE_FULL,
11 ICE_MODE_LITE
12};
13
14/** ICE Role */
15enum ice_role {
16 ICE_ROLE_UNKNOWN = 0,
17 ICE_ROLE_CONTROLLING,
18 ICE_ROLE_CONTROLLED
19};
20
21/** ICE Component ID */
22enum ice_compid {
23 ICE_COMPID_RTP = 1,
24 ICE_COMPID_RTCP = 2
25};
26
27/** ICE Nomination */
28enum ice_nomination {
29 ICE_NOMINATION_REGULAR = 0,
30 ICE_NOMINATION_AGGRESSIVE
31};
32
33/** ICE Candidate type */
34enum 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 */
42enum 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 */
49enum 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
57struct ice;
58struct ice_cand;
59struct icem;
60struct turnc;
61
62/** ICE Configuration */
63struct 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
70typedef void (ice_connchk_h)(int err, bool update, void *arg);
71
72
73/* ICE Media */
74int 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);
78struct ice_conf *icem_conf(struct icem *icem);
79enum ice_role icem_local_role(const struct icem *icem);
80void icem_set_conf(struct icem *icem, const struct ice_conf *conf);
81void icem_set_role(struct icem *icem, enum ice_role role);
82void icem_set_name(struct icem *icem, const char *name);
83int icem_comp_add(struct icem *icem, unsigned compid, void *sock);
84int icem_cand_add(struct icem *icem, unsigned compid, uint16_t lprio,
85 const char *ifname, const struct sa *addr);
86
87int icem_lite_set_default_candidates(struct icem *icem);
88bool icem_verify_support(struct icem *icem, unsigned compid,
89 const struct sa *raddr);
90int icem_conncheck_start(struct icem *icem);
91void icem_conncheck_stop(struct icem *icem, int err);
92int icem_add_chan(struct icem *icem, unsigned compid, const struct sa *raddr);
93bool icem_mismatch(const struct icem *icem);
94void icem_update(struct icem *icem);
95int ice_sdp_decode(struct icem *ice, const char *name, const char *value);
96int icem_sdp_decode(struct icem *icem, const char *name, const char *value);
97int icem_debug(struct re_printf *pf, const struct icem *icem);
98struct list *icem_lcandl(const struct icem *icem);
99struct list *icem_rcandl(const struct icem *icem);
100struct list *icem_checkl(const struct icem *icem);
101struct list *icem_validl(const struct icem *icem);
102const struct sa *icem_cand_default(struct icem *icem, unsigned compid);
103const struct sa *icem_selected_laddr(const struct icem *icem, unsigned compid);
104const struct ice_cand *icem_selected_lcand(const struct icem *icem,
105 unsigned compid);
106const struct ice_cand *icem_selected_rcand(const struct icem *icem,
107 unsigned compid);
108void ice_candpair_set_states(struct icem *icem);
109void icem_cand_redund_elim(struct icem *icem);
110int icem_comps_set_default_cand(struct icem *icem);
111struct stun *icem_stun(struct icem *icem);
112int icem_set_turn_client(struct icem *icem, unsigned compid,
113 struct turnc *turnc);
114
115
116bool ice_remotecands_avail(const struct icem *icem);
117int ice_cand_encode(struct re_printf *pf, const struct ice_cand *cand);
118int ice_remotecands_encode(struct re_printf *pf, const struct icem *icem);
119struct ice_cand *icem_cand_find(const struct list *lst, unsigned compid,
120 const struct sa *addr);
121int icem_lcand_add(struct icem *icem, struct ice_cand *base,
122 enum ice_cand_type type,
123 const struct sa *addr);
124struct ice_cand *icem_lcand_base(struct ice_cand *lcand);
125const struct sa *icem_lcand_addr(const struct ice_cand *cand);
126enum ice_cand_type icem_cand_type(const struct ice_cand *cand);
127
128
129extern const char ice_attr_cand[];
130extern const char ice_attr_lite[];
131extern const char ice_attr_mismatch[];
132extern const char ice_attr_pwd[];
133extern const char ice_attr_remote_cand[];
134extern const char ice_attr_ufrag[];
135
136
137const char *ice_cand_type2name(enum ice_cand_type type);
138enum ice_cand_type ice_cand_name2type(const char *name);
139const char *ice_role2name(enum ice_role role);
140const char *ice_candpair_state2name(enum ice_candpair_state st);
141
142
143uint32_t ice_cand_calc_prio(enum ice_cand_type type, uint16_t local,
144 unsigned compid);
145
146
147/** Defines an SDP candidate attribute */
148struct 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
159int ice_cand_attr_encode(struct re_printf *pf,
160 const struct ice_cand_attr *cand);
161int ice_cand_attr_decode(struct ice_cand_attr *cand, const char *val);