tsip.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tsip.h
  23. * @brief SIP (RFC 3261) and 3GPP IMS/LTE (TS 24.229) implementation.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYSIP_TSIP_H
  29. #define TINYSIP_TSIP_H
  30. #include "tinysip_config.h"
  31. #include "tinysip/tsip_ssession.h"
  32. #include "tinysip/tsip_timers.h"
  33. #include "tinysip/tsip_event.h"
  34. #include "tinysip/transports/tsip_transport.h"
  35. #include "tinysip/tsip_uri.h"
  36. #include "tinysip/sigcomp/tsip_sigcomp.h"
  37. #include "tinynet.h"
  38. #include "tsk_runnable.h"
  39. TSIP_BEGIN_DECLS
  40. #define TSIP_IARI_GSMAIS "urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-is"
  41. #define TSIP_IARI_QUOTED_GSMAIS "\"" TSIP_IARI_GSMAIS "\""
  42. #define TSIP_ICSI_MMTEL_PSVOICE "urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"
  43. #define TSIP_ICSI_QUOTED_MMTEL_PSVOICE "\"" TSIP_ICSI_MMTEL_PSVOICE "\""
  44. #define TSIP_STACK(self) ((tsip_stack_t*)(self))
  45. typedef uint8_t amf_t[2];
  46. typedef uint8_t operator_id_t[16];
  47. // @tinyWRAP
  48. typedef enum tsip_stack_mode_e {
  49. tsip_stack_mode_ua,
  50. tsip_stack_mode_p2p,
  51. tsip_stack_mode_webrtc2sip,
  52. tsip_stack_mode_mcu
  53. }
  54. tsip_stack_mode_t;
  55. #define TSIP_STACK_MODE_IS_SERVER(stack) ((stack)->network.mode == tsip_stack_mode_webrtc2sip || (stack)->network.mode == tsip_stack_mode_mcu)
  56. #define TSIP_STACK_MODE_IS_CLIENT(stack) (!TSIP_STACK_MODE_IS_SERVER((stack)))
  57. typedef enum tsip_stack_param_type_e {
  58. tsip_pname_null = 0,
  59. /* === Identity === */
  60. tsip_pname_display_name,
  61. tsip_pname_impu,
  62. tsip_pname_preferred_id,
  63. tsip_pname_impi,
  64. tsip_pname_password,
  65. /* === SigComp === */
  66. tsip_pname_sigcomp,
  67. tsip_pname_sigcomp_add_compartment,
  68. tsip_pname_sigcomp_remove_compartment,
  69. /* === Network === */
  70. tsip_pname_realm,
  71. tsip_pname_local_ip,
  72. tsip_pname_local_port,
  73. tsip_pname_aor,
  74. tsip_pname_discovery_naptr,
  75. tsip_pname_discovery_dhcp,
  76. tsip_pname_proxy_cscf,
  77. tsip_pname_dnsserver,
  78. tsip_pname_max_fds,
  79. tsip_pname_mode,
  80. /* === Security === */
  81. tsip_pname_early_ims,
  82. tsip_pname_secagree_ipsec,
  83. tsip_pname_secagree_tls,
  84. tsip_pname_amf,
  85. tsip_pname_operator_id,
  86. tsip_pname_tls_certs,
  87. tsip_pname_ipsec_params,
  88. /* === Dummy Headers === */
  89. tsip_pname_header,
  90. /* Nat Traversal */
  91. tsip_pname_stun_enabled,
  92. tsip_pname_stun_server,
  93. tsip_pname_stun_cred,
  94. /* === User Data === */
  95. tsip_pname_userdata,
  96. }
  97. tsip_stack_param_type_t;
  98. /**@ingroup tsip_stack_group
  99. * @def TSIP_STACK_SET_NULL
  100. * Ends the stack parameters. Mandatory and should be the last one.
  101. */
  102. #define TSIP_STACK_SET_NULL() tsip_pname_null
  103. /* === Identity === */
  104. /**@ingroup tsip_stack_group
  105. * @def TSIP_STACK_SET_DISPLAY_NAME
  106. * Sets the user's display name. Used in SIP 'From' and 'To' headers.
  107. * @param NAME_STR The user's display name.
  108. * @code
  109. * int ret = tsip_stack_set(stack,
  110. * TSIP_STACK_SET_DISPLAY_NAME("john doe"),
  111. * TSIP_STACK_SET_NULL());
  112. * @endcode
  113. */
  114. /**@ingroup tsip_stack_group
  115. * @def TSIP_STACK_SET_IMPU
  116. * Sets the user's IMPU (IMS Public Identity).
  117. * @param URI_STR A valid SIP/SIPS/tel URI string.
  118. * @code
  119. * int ret = tsip_stack_set(stack,
  120. * TSIP_STACK_SET_IMPU("sip:johndoe@open-ims.test"),
  121. * TSIP_STACK_SET_NULL());
  122. * @endcode
  123. */
  124. /**@ingroup tsip_stack_group
  125. * @def TSIP_STACK_SET_PREFERRED_IDENTITY
  126. * Sets the user's Preferred Identity. Used to populate the P-Preferred-Identity header.
  127. * @param URI_STR A valid SIP/SIPS/tel URI string.
  128. * @code
  129. * int ret = tsip_stack_set(stack,
  130. * TSIP_STACK_SET_PREFERRED_IDENTITY("sip:johndoe@open-ims.test"),
  131. * TSIP_STACK_SET_NULL());
  132. * @endcode
  133. */
  134. /**@ingroup tsip_stack_group
  135. * @def TSIP_STACK_SET_IMPI
  136. * Sets the user's IMPI (IMS Private Identity).
  137. * @param IMPI_STR Any string.
  138. * @code
  139. * int ret = tsip_stack_set(stack,
  140. * TSIP_STACK_SET_IMPI("johndoe@open-ims.test"),
  141. * TSIP_STACK_SET_NULL());
  142. * @endcode
  143. */
  144. /**@ingroup tsip_stack_group
  145. * @def TSIP_STACK_SET_PASSWORD
  146. * Sets the user's password.
  147. * @param PASSORD_STR Any string.
  148. * @code
  149. * int ret = tsip_stack_set(stack,
  150. * TSIP_STACK_SET_PASSWORD("mysecret"),
  151. * TSIP_STACK_SET_NULL());
  152. * @endcode
  153. */
  154. #define TSIP_STACK_SET_DISPLAY_NAME(NAME_STR) tsip_pname_display_name, (const char*)NAME_STR
  155. #define TSIP_STACK_SET_IMPU(URI_STR) tsip_pname_impu, (const char*)URI_STR
  156. #define TSIP_STACK_SET_PREFERRED_IDENTITY(URI_STR) tsip_pname_preferred_id, (const char*)URI_STR
  157. #define TSIP_STACK_SET_IMPI(IMPI_STR) tsip_pname_impi, (const char*)IMPI_STR
  158. #define TSIP_STACK_SET_PASSWORD(PASSORD_STR) tsip_pname_password, (const char*)PASSORD_STR
  159. /* === SigComp === */
  160. /**@ingroup tsip_stack_group
  161. * @def TSIP_STACK_SET_SIGCOMP
  162. * Sets the SigComp parameters. It's not mandatory to call this function in order to use SigComp.
  163. * It should be called to change default parameters. As these parameters will be shared by all compartments,
  164. * you should call this function before adding any compartment.
  165. * @param DMS_UINT Decompression Memory Size. Default value is 8192.
  166. * @param SMS_UINT State Memory Size. Default value is 8192.
  167. * @param CPB_UINT Cycles Per Bit. Default value is 64.
  168. * @param PRES_DICT_BOOL Indicates whether to enable Presence dictionary (RFC 5112) or not. Default value is @a tsk_false.
  169. * @code
  170. * int ret = tsip_stack_set(stack,
  171. * TSIP_STACK_SET_SIGCOMP(8192, 8192, 64, tsk_true),
  172. * TSIP_STACK_SET_NULL());
  173. * @endcode
  174. */
  175. /**@ingroup tsip_stack_group
  176. * @def TSIP_STACK_SET_SIGCOMP_NEW_COMPARTMENT
  177. * Add New unique compartment identifier to the stack. This compartment will be closed (not removed) when the stack is stopped.
  178. * A any time, you can remove this compartment by using @ref TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT().
  179. * @param COMPARTMENT_ID_STR The id of the compartment to add. Should be unique.
  180. * The identifier will be used to in the sip headers (as per RFC 5049) "AS IS".<br>
  181. * @sa @ref TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT()
  182. *
  183. * @code
  184. * int ret = tsip_stack_set(stack,
  185. * TSIP_STACK_SET_NEW_SIGCOMP_COMPARTMENT("urn:uuid:0C67446E-F1A1-11D9-94D3-000A95A0E128"),
  186. * TSIP_STACK_SET_NULL());
  187. * @endcode
  188. */
  189. /**@ingroup tsip_stack_group
  190. * @def TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT
  191. * Removes a SigComp compartment. This will close the compartment and release all its states.
  192. * You should only close a compartment if there is no outgoing session using it. In all cases, all compartments
  193. * will be closed when the stack is destroyed or stopped.
  194. * @param COMPARTMENT_ID_STR The id of the compartment to close.
  195. * @sa @ref TSIP_STACK_SET_SIGCOMP_NEW_COMPARTMENT()
  196. *
  197. * @code
  198. * int ret = tsip_stack_set(stack,
  199. * TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT("urn:uuid:0C67446E-F1A1-11D9-94D3-000A95A0E128"),
  200. * TSIP_STACK_SET_NULL());
  201. * @endcode
  202. */
  203. #define TSIP_STACK_SET_SIGCOMP(DMS_UINT, SMS_UINT, CPB_UINT, PRES_DICT_BOOL) tsip_pname_sigcomp, (unsigned)DMS_UINT, (unsigned)SMS_UINT, (unsigned)CPB_UINT, (tsk_bool_t)PRES_DICT_BOOL
  204. #define TSIP_STACK_SET_SIGCOMP_NEW_COMPARTMENT(COMPARTMENT_ID_STR) tsip_pname_sigcomp_add_compartment, (const char*)COMPARTMENT_ID_STR
  205. #define TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT(COMPARTMENT_ID_STR) tsip_pname_sigcomp_remove_compartment, (const char*)COMPARTMENT_ID_STR
  206. /* === Network === */
  207. /**@ingroup tsip_stack_group
  208. * @def TSIP_STACK_SET_REALM
  209. * Sets the domain name.
  210. * @param URI_STR A valid SIP/SIPS URI string.
  211. * @code
  212. * int ret = tsip_stack_set(stack,
  213. * TSIP_STACK_SET_REALM("sip:open-ims.test"),
  214. * TSIP_STACK_SET_NULL());
  215. * @endcode
  216. */
  217. /**@ingroup tsip_stack_group
  218. * @def TSIP_STACK_SET_LOCAL_IP
  219. * Sets the user's local IP address.
  220. * @param IP_STR IPv4/IPv6 IP address or FQDN.
  221. * @code
  222. * int ret = tsip_stack_set(stack,
  223. * TSIP_STACK_SET_LOCAL_IP("fe80::"),
  224. * TSIP_STACK_SET_NULL());
  225. * @endcode
  226. *
  227. * @sa @ref TSIP_STACK_SET_LOCAL_PORT()<br>@ref TSIP_STACK_SET_AOR()
  228. */
  229. /**@ingroup tsip_stack_group
  230. * @def TSIP_STACK_SET_LOCAL_PORT
  231. * Sets the user's local Port to bind to.
  232. * @param PORT_UINT Port number. Should be between 0x0400 and 0xFFFF.
  233. * @code
  234. * int ret = tsip_stack_set(stack,
  235. * TSIP_STACK_SET_LOCAL_PORT(5060),
  236. * TSIP_STACK_SET_NULL());
  237. * @endcode
  238. *
  239. * @sa @ref TSIP_STACK_SET_LOCAL_IP()<br>@ref TSIP_STACK_SET_AOR()
  240. */
  241. /**@ingroup tsip_stack_group
  242. * @def TSIP_STACK_SET_AOR
  243. * Sets the SIP AOR to use for all outgoing requests.
  244. * @param IP_STR The IP address. Should be numeric IP string. e.g. 192.168.0.16.
  245. * Will be ignored if null or empty.
  246. * @param PORT_UINT Port number. Should be between 0x0400 and 0xFFFF.
  247. * Will be ignored if equals to zero.
  248. * @code
  249. * int ret = tsip_stack_set(stack,
  250. * TSIP_STACK_SET_AOR("fe80::", 1234),
  251. * TSIP_STACK_SET_NULL());
  252. * @endcode
  253. *
  254. * @sa @ref TSIP_STACK_SET_LOCAL_IP()<br>@ref TSIP_STACK_SET_LOCAL_PORT()
  255. */
  256. /**@ingroup tsip_stack_group
  257. * @def TSIP_STACK_SET_DISCOVERY_NAPTR
  258. * Whether to use DNS NAPTR for Proxy-CSCF discovery. Default is false. However, if the Proxy-CSCF IP address
  259. * is missing, then this option will be enabled by default.
  260. * @param ENABLED_BOOL @a tsk_true (1) or @a tsk_false (0).
  261. * @code
  262. * int ret = tsip_stack_set(stack,
  263. * TSIP_STACK_SET_DISCOVERY_NAPTR(tsk_true),
  264. * TSIP_STACK_SET_NULL());
  265. * @endcode
  266. *
  267. * @sa @ref TSIP_STACK_SET_DISCOVERY_DHCP()
  268. */
  269. /**@ingroup tsip_stack_group
  270. * @def TSIP_STACK_SET_DISCOVERY_DHCP
  271. * Whether to use DHCPv4/v6 for Proxy-CSCF discovery. Default is false. The IP version (v4/v6) of the DHCP protocol
  272. * to use will depend on the Proxy-CSCF address type.
  273. * @param ENABLED_BOOL @a tsk_true (1) or @a tsk_false (0).
  274. * @code
  275. * int ret = tsip_stack_set(stack,
  276. * TSIP_STACK_SET_DISCOVERY_DHCP(tsk_false),
  277. * TSIP_STACK_SET_NULL());
  278. * @endcode
  279. *
  280. * @sa @ref TSIP_STACK_SET_DISCOVERY_NAPTR()
  281. */
  282. /**@ingroup tsip_stack_group
  283. * @def TSIP_STACK_SET_PROXY_CSCF
  284. * Configures the Proxy-CSCF.
  285. * @param FQDN_STR The IP address (v4/v6) or FQDN of the Proxy-CSCF.
  286. * @param PORT_UINT The port.
  287. * @param TRANSPORT_STR The transport type. Should be: @a "udp" or @a "tcp" or @a "tls" or @a "sctp". Default is @a "udp".
  288. * @param IP_VERSION_STR The IP version to use. Should be: @a "ipv4" or @a "ipv6" or @a "ipv46". This parameter is useful when
  289. * @a FQDN_STR parameter is a domain name. default is @a "ipv4".
  290. * @code
  291. * int ret = tsip_stack_set(stack,
  292. * TSIP_STACK_SET_PROXY_CSCF("pcscf-doubango.org", 4060, "tcp", "ipv6"),
  293. * TSIP_STACK_SET_NULL());
  294. * @endcode
  295. *
  296. * @sa @ref TSIP_STACK_SET_DISCOVERY_DHCP()<br>@ref TSIP_STACK_SET_DISCOVERY_NAPTR()
  297. */
  298. /**@ingroup tsip_stack_group
  299. * @def TSIP_STACK_SET_DNS_SERVER
  300. * Adds a DNS server.
  301. * @param IP_STR The IP address or FQDN of the DNS server to add.
  302. * @code
  303. // Add two new DNS servers (IPv6 and IPv4)
  304. int ret = tsip_stack_set(stack,
  305. TSIP_STACK_SET_DNS_SERVER("192.16.16.9"),
  306. TSIP_STACK_SET_DNS_SERVER("fe::"),
  307. TSIP_STACK_SET_NULL());
  308. * @endcode
  309. */
  310. /**@ingroup tsip_stack_group
  311. * @def TSIP_STACK_SET_MODE_SERVER
  312. * Configure the stack to be used as server. Cannot be changed later.
  313. * @code
  314. int ret = tsip_stack_set(stack,
  315. TSIP_STACK_SET_MODE_SERVER(),
  316. TSIP_STACK_SET_NULL());
  317. * @endcode
  318. */
  319. #define TSIP_STACK_SET_REALM(URI_STR) tsip_pname_realm, (const char*)URI_STR
  320. #define TSIP_STACK_SET_LOCAL_IP_2(TRANSPORT_STR, IP_STR) tsip_pname_local_ip, (const char*)TRANSPORT_STR, (const char*)IP_STR
  321. #define TSIP_STACK_SET_LOCAL_PORT_2(TRANSPORT_STR, PORT_UINT) tsip_pname_local_port, (const char*)TRANSPORT_STR, (unsigned)PORT_UINT
  322. #define TSIP_STACK_SET_LOCAL_IP(IP_STR) TSIP_STACK_SET_LOCAL_IP_2(tsk_null, IP_STR)// @deprecated
  323. #define TSIP_STACK_SET_LOCAL_PORT(PORT_UINT) TSIP_STACK_SET_LOCAL_PORT_2(tsk_null, PORT_UINT)// @deprecated
  324. #define TSIP_STACK_SET_AOR_2(TRANSPORT_STR, IP_STR, PORT_UINT) tsip_pname_aor, (const char*)TRANSPORT_STR, (const char*)IP_STR, (unsigned)PORT_UINT
  325. #define TSIP_STACK_SET_AOR(IP_STR, PORT_UINT) TSIP_STACK_SET_AOR_2(tsk_null, IP_STR, PORT_UINT)// @deprecated
  326. #define TSIP_STACK_SET_DISCOVERY_NAPTR(ENABLED_BOOL) tsip_pname_discovery_naptr, (tsk_bool_t)ENABLED_BOOL
  327. #define TSIP_STACK_SET_DISCOVERY_DHCP(ENABLED_BOOL) tsip_pname_discovery_dhcp, (tsk_bool_t)ENABLED_BOOL
  328. #define TSIP_STACK_SET_PROXY_CSCF(FQDN_STR, PORT_UINT, TRANSPORT_STR, IP_VERSION_STR) tsip_pname_proxy_cscf, (const char*)FQDN_STR, (unsigned)PORT_UINT, (const char*)TRANSPORT_STR, (const char*)IP_VERSION_STR
  329. #define TSIP_STACK_SET_DNS_SERVER(IP_STR) tsip_pname_dnsserver, (const char*)IP_STR
  330. #define TSIP_STACK_SET_MAX_FDS(MAX_FDS_UINT) tsip_pname_max_fds, (unsigned)MAX_FDS_UINT
  331. #define TSIP_STACK_SET_MODE(MODE_ENUM) tsip_pname_mode, (tsip_stack_mode_t)MODE_ENUM
  332. /* === Security === */
  333. /**@ingroup tsip_stack_group
  334. * @def TSIP_STACK_SET_EARLY_IMS
  335. * Whether to enable 3GPP Early-IMS Security as per 3GPP TS 33.978.
  336. * @param ENABLED_BOOL @a tsk_true (1) or @a tsk_false (0).
  337. * @code
  338. * int ret = tsip_stack_set(stack,
  339. * TSIP_STACK_SET_EARLY_IMS(tsk_false),
  340. * TSIP_STACK_SET_NULL());
  341. * @endcode
  342. */
  343. /**@ingroup tsip_stack_group
  344. * @def TSIP_STACK_SET_SECAGREE_IPSEC
  345. * Whether to enable IPSec security agreement as per IETF RFC 3329.
  346. * @param ENABLED_BOOL @a tsk_true (1) or @a tsk_false (0).
  347. * @code
  348. * int ret = tsip_stack_set(stack,
  349. * TSIP_STACK_SET_SECAGREE_IPSEC(tsk_true),
  350. * TSIP_STACK_SET_NULL());
  351. * @endcode
  352. *
  353. * @sa @ref TSIP_STACK_SET_IPSEC_PARAMS()
  354. */
  355. /**@ingroup tsip_stack_group
  356. * @def TSIP_STACK_SET_SECAGREE_TLS
  357. * Whether to enable TLS security agreement as per IETF RFC 3329.
  358. * @param ENABLED_BOOL @a tsk_true (1) or @a tsk_false (0).
  359. * @code
  360. * int ret = tsip_stack_set(stack,
  361. * TSIP_STACK_SET_SECAGREE_TLS(tsk_true),
  362. * TSIP_STACK_SET_NULL());
  363. * @endcode
  364. *
  365. * @sa @ref TSIP_STACK_SET_IPSEC_PARAMS()
  366. */
  367. /**@ingroup tsip_stack_group
  368. * @def TSIP_STACK_SET_IMS_AKA_AMF
  369. * Sets AMF (Authentication Management Field) value to use for IMS-AKA authentication.
  370. * @param AMF_UINT16 16-bit value.
  371. * @code
  372. * int ret = tsip_stack_set(stack,
  373. * TSIP_STACK_SET_IMS_AKA_AMF(0x3FB6),
  374. * TSIP_STACK_SET_NULL());
  375. * @endcode
  376. *
  377. * @sa @ref TSIP_STACK_SET_IMS_AKA_OPERATOR_ID()
  378. */
  379. /**@ingroup tsip_stack_group
  380. * @def TSIP_STACK_SET_IMS_AKA_OPERATOR_ID
  381. * Sets the operator identifier value to use for IMS-AKA authentication.
  382. * @param OPID_HEX_STR 128-bit value as hex-string. If the length of the value supplied by the user is less than 128 bits,
  383. * then it will be padded with zeros.
  384. * @code
  385. * int ret = tsip_stack_set(stack,
  386. * TSIP_STACK_SET_IMS_AKA_OPERATOR_ID("0x5FABC9"), // Will be padded with zeros
  387. * TSIP_STACK_SET_NULL());
  388. * @endcode
  389. *
  390. * @sa @ref TSIP_STACK_SET_IMS_AKA_AMF()
  391. */
  392. /**@ingroup tsip_stack_group
  393. * @def TSIP_STACK_SET_IPSEC_PARAMS
  394. * Sets the IPSec parameters. To enable IPSec security agreement you should use @ref TSIP_STACK_SET_SECAGREE_IPSEC(tsk_true).
  395. * @param ALG_STR Algorithm. Should be: @a "hmac-sha-1-96" or @a "hmac-md5-96". Default is @a "hmac-md5-96".
  396. * @param EALG_STR Encryption Algorithm. Should be: @a "des-ede3-cbc" or @a "aes" or @a "null". Default is @a "null".
  397. * @param MODE_STR Mode. Should be: @a "tun" or @a "trans". Default is @a "trans".
  398. * @param PROTOCOL_STR Protocol. Should be @a "ah" or @a "esp" or @a "ah/esp". Default is @a "esp".
  399. * @code
  400. * int ret = tsip_stack_set(stack,
  401. * TSIP_STACK_SET_SECAGREE_IPSEC(tsk_true),
  402. TSIP_STACK_SET_IPSEC_PARAMS("hmac-md5-96", "des-ede3-cbc", "trans", "esp"),
  403. * TSIP_STACK_SET_NULL());
  404. * @endcode
  405. *
  406. * @sa @ref TSIP_STACK_SET_TLS_CERTS()
  407. */
  408. /**@ingroup tsip_stack_group
  409. * @def TSIP_STACK_SET_TLS_CERTS
  410. * Sets TLS certificate files. To enable TLS security agreement you should use @ref TSIP_STACK_SET_SECAGREE_TLS(tsk_true).
  411. * @param CA_FILE_STR CA file.
  412. * @param PUB_FILE_STR Public cert. file.
  413. * @param PRIV_FILE_STR Private cert. file.
  414. * @code
  415. * int ret = tsip_stack_set(stack,
  416. * TSIP_STACK_SET_TLS_CERTS("C:\\tls\\ca.pki-crt.pem", "C:\\tls\\pub-crt.pem", "C:\\tls\\priv-key.pem"),
  417. * TSIP_STACK_SET_NULL());
  418. * @endcode
  419. *
  420. * @sa @ref TSIP_STACK_SET_IPSEC_PARAMS()
  421. */
  422. #define TSIP_STACK_SET_EARLY_IMS(ENABLED_BOOL) tsip_pname_early_ims, (tsk_bool_t)ENABLED_BOOL
  423. #define TSIP_STACK_SET_SECAGREE_IPSEC_2(TRANSPORT_STR, ENABLED_BOOL) tsip_pname_secagree_ipsec, (const char*)TRANSPORT_STR, (tsk_bool_t)ENABLED_BOOL
  424. #define TSIP_STACK_SET_SECAGREE_IPSEC(ENABLED_BOOL) TSIP_STACK_SET_SECAGREE_IPSEC_2(tsk_null, ENABLED_BOOL) // @deprecated
  425. #define TSIP_STACK_SET_SECAGREE_TLS(ENABLED_BOOL) tsip_pname_secagree_tls, (tsk_bool_t)ENABLED_BOOL
  426. #define TSIP_STACK_SET_IMS_AKA_AMF(AMF_UINT16) tsip_pname_amf, (uint16_t)AMF_UINT16
  427. #define TSIP_STACK_SET_IMS_AKA_OPERATOR_ID(OPID_HEX_STR) tsip_pname_operator_id, (const char*)OPID_HEX_STR
  428. #define TSIP_STACK_SET_IPSEC_PARAMS(ALG_STR, EALG_STR, MODE_STR, PROTOCOL_STR) tsip_pname_ipsec_params, (const char*)ALG_STR, (const char*)EALG_STR, (const char*)MODE_STR, (const char*)PROTOCOL_STR
  429. #define TSIP_STACK_SET_TLS_CERTS(CA_FILE_STR, PUB_FILE_STR, PRIV_FILE_STR) TSIP_STACK_SET_TLS_CERTS_2(CA_FILE_STR, PUB_FILE_STR, PRIV_FILE_STR, tsk_false)
  430. #define TSIP_STACK_SET_TLS_CERTS_2(CA_FILE_STR, PUB_FILE_STR, PRIV_FILE_STR, VERIF_BOOL) tsip_pname_tls_certs, (const char*)CA_FILE_STR, (const char*)PUB_FILE_STR, (const char*)PRIV_FILE_STR, (tsk_bool_t)VERIF_BOOL
  431. /* === Headers === */
  432. /**@ingroup tsip_stack_group
  433. * @def TSIP_STACK_SET_HEADER
  434. * Adds or updates a stack-level header.
  435. * @param NAME_STR The name of the header to add or update.
  436. * @param VALUE_STR The value of the header to add or update.
  437. * @code
  438. * int ret = tsip_stack_set(stack,
  439. * TSIP_STACK_SET_HEADER("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0"),
  440. * TSIP_STACK_SET_HEADER("Allow", "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER"),
  441. * TSIP_STACK_SET_NULL());
  442. * @endcode
  443. *
  444. * @sa @ref TSIP_STACK_UNSET_HEADER()
  445. */
  446. /**@ingroup tsip_stack_group
  447. * @def TSIP_STACK_SET_HEADER
  448. * Removes a stack-level header.
  449. * @param NAME_STR The name of the header to remove.
  450. * @code
  451. * int ret = tsip_stack_set(stack,
  452. * TSIP_STACK_UNSET_HEADER("User-Agent"),
  453. * TSIP_STACK_UNSET_HEADER("Allow"),
  454. * TSIP_STACK_UNSET_HEADER("My_Header"),
  455. * TSIP_STACK_SET_NULL());
  456. * @endcode
  457. *
  458. * @sa @ref TSIP_STACK_SET_HEADER()
  459. */
  460. #define TSIP_STACK_SET_HEADER(NAME_STR, VALUE_STR) tsip_pname_header, (const char*)NAME_STR, (const char*)VALUE_STR
  461. #define TSIP_STACK_UNSET_HEADER(NAME_STR) TSIP_STACK_SET_HEADER(NAME_STR, ((const char*)-1))
  462. /* === NAT Traversal === */
  463. /**@ingroup tsip_stack_group
  464. * @def TSIP_STACK_SET_STUN_SERVER
  465. * Sets the IP address and port of the STUN2 server. Also used for TURN.
  466. * @param IP_STR The IPv4/IPv6 address for FQDN of the STUN2/TURN address.
  467. * @param PORT_UINT The server port (default is 3478 for both TCP and UDP, and 5349 for TLS)
  468. * @code
  469. * int ret = tsip_stack_set(stack,
  470. * TSIP_STACK_SET_STUN_SERVER("numb.viagenie.ca", 3478),
  471. * TSIP_STACK_SET_NULL());
  472. * @endcode
  473. *
  474. * @sa @ref TSIP_STACK_SET_STUN_CRED()
  475. */
  476. /**@ingroup tsip_stack_group
  477. * @def TSIP_STACK_SET_STUN_CRED
  478. * Sets STUN/TURN credentials.
  479. * @param USR_STR The login.
  480. * @param PASSORD_STR The password
  481. * @code
  482. * int ret = tsip_stack_set(stack,
  483. * TSIP_STACK_SET_STUN_CRED("bob@open-ims.test", "mysecret"),
  484. * TSIP_STACK_SET_NULL());
  485. * @endcode
  486. *
  487. * @sa @ref TSIP_STACK_SET_STUN_SERVER()
  488. */
  489. #define TSIP_STACK_SET_STUN_SERVER(IP_STR, PORT_UINT) tsip_pname_stun_server, (const char*)IP_STR, (unsigned)PORT_UINT
  490. #define TSIP_STACK_SET_STUN_CRED(USR_STR, PASSORD_STR) tsip_pname_stun_cred, (const char*)USR_STR, (const char*)PASSORD_STR
  491. #define TSIP_STACK_SET_STUN_ENABLED(ENABLED_BOOL) tsip_pname_stun_enabled, (tsk_bool_t)ENABLED_BOOL
  492. /* === User Data === */
  493. /**@ingroup tsip_stack_group
  494. * @def TSIP_STACK_SET_USERDATA
  495. * Sets opaque user's data returned in each callback. Could be used to store the context.
  496. * @param DATA_PTR Pointer to the user data.
  497. * @code
  498. * const void* context;
  499. * int ret = tsip_stack_set(stack,
  500. * TSIP_STACK_SET_USERDATA(context),
  501. * TSIP_STACK_SET_NULL());
  502. * @endcode
  503. */
  504. #define TSIP_STACK_SET_USERDATA(DATA_PTR) tsip_pname_userdata, (const void*)DATA_PTR
  505. /* 3GPP IMS/LTE stack (for internal use). only tsip_stack_handle_t should be visible. */
  506. typedef struct tsip_stack_s {
  507. TSK_DECLARE_RUNNABLE;
  508. TSK_DECLARE_SAFEOBJ;
  509. tsk_timer_manager_handle_t* timer_mgr_global;
  510. tsk_bool_t started;
  511. tsip_stack_callback_f callback;
  512. /* === Identity === */
  513. struct {
  514. char* display_name;
  515. tsip_uri_t *impu;
  516. tsip_uri_t *preferred;
  517. char *impi;
  518. char *password;
  519. } identity;
  520. /* === SigComp === */
  521. struct {
  522. tsip_sigcomp_handle_t* handle;
  523. unsigned dms;
  524. unsigned sms;
  525. unsigned cpb;
  526. tsk_bool_t sip_dict;
  527. tsk_bool_t pres_dict;
  528. } sigcomp;
  529. /* === Network === */
  530. struct {
  531. tsip_stack_mode_t mode;
  532. char *local_ip[TSIP_TRANSPORT_IDX_MAX];
  533. tnet_port_t local_port[TSIP_TRANSPORT_IDX_MAX];
  534. tsk_bool_t local_ip_is_set_by_user[TSIP_TRANSPORT_IDX_MAX]; // whether the address (ip and port) is set by the user or retrieved
  535. char *proxy_cscf[TSIP_TRANSPORT_IDX_MAX];
  536. tnet_port_t proxy_cscf_port[TSIP_TRANSPORT_IDX_MAX];
  537. tnet_socket_type_t proxy_cscf_type[TSIP_TRANSPORT_IDX_MAX];
  538. tnet_socket_type_t transport_types[TSIP_TRANSPORT_IDX_MAX];
  539. int32_t transport_idx_default;
  540. tsip_uri_t *realm;
  541. //! IP adddress and port to use as AOR (user-defined)
  542. struct {
  543. char* ip[TSIP_TRANSPORT_IDX_MAX];
  544. tnet_port_t port[TSIP_TRANSPORT_IDX_MAX];
  545. } aor;
  546. tsk_bool_t discovery_naptr;
  547. tsk_bool_t discovery_dhcp;
  548. tsk_size_t max_fds;
  549. } network;
  550. /* === Security === */
  551. struct {
  552. char* secagree_mech;
  553. tsk_bool_t earlyIMS;
  554. operator_id_t operator_id;
  555. amf_t amf;
  556. /* IPSec */
  557. struct {
  558. char* alg;
  559. char* ealg;
  560. char* mode;
  561. char* protocol;
  562. } ipsec;
  563. tsk_bool_t enable_secagree_ipsec;
  564. /* TLS */
  565. struct {
  566. char* ca;
  567. char* pbk;
  568. char* pvk;
  569. tsk_bool_t verify;
  570. } tls;
  571. tsk_bool_t enable_secagree_tls;
  572. } security;
  573. tsip_uris_L_t* paths;
  574. tsip_uris_L_t* service_routes;
  575. tsip_uris_L_t* associated_uris;
  576. /* DNS context */
  577. tnet_dns_ctx_t *dns_ctx;
  578. /* NAT Traversal context */
  579. struct {
  580. // STUN
  581. struct {
  582. char* ip;
  583. tnet_port_t port;
  584. char* login;
  585. char* pwd;
  586. tsk_bool_t enabled;
  587. } stun;
  588. struct tnet_nat_ctx_s* ctx;
  589. } natt;
  590. /* DHCP context */
  591. /* QoS */
  592. /* Internals. */
  593. //tsk_timer_manager_handle_t* timer_mgr;
  594. tsip_timers_t timers;
  595. tsip_ssessions_L_t *ssessions;
  596. tsk_params_L_t *headers;
  597. const void* userdata;
  598. /* Layers */
  599. struct tsip_dialog_layer_s *layer_dialog;
  600. struct tsip_transac_layer_s *layer_transac;
  601. struct tsip_transport_layer_s *layer_transport;
  602. }
  603. tsip_stack_t;
  604. TINYSIP_API tsip_stack_handle_t *tsip_stack_create(tsip_stack_callback_f callback, const char* realm_uri, const char* impi_uri, const char* impu_uri, ...);
  605. TINYSIP_API int tsip_stack_start(tsip_stack_handle_t *self);
  606. TINYSIP_API int tsip_stack_set(tsip_stack_handle_t *self, ...);
  607. TINYSIP_API const void* tsip_stack_get_userdata(const tsip_stack_handle_t *self);
  608. TINYSIP_API tnet_dns_ctx_t* tsip_stack_get_dnsctx(tsip_stack_handle_t *self);
  609. TINYSIP_API tsip_uri_t* tsip_stack_get_preferred_id(tsip_stack_handle_t *self);
  610. TINYSIP_API int tsip_stack_get_local_ip_n_port(const tsip_stack_handle_t *self, const char* protocol, tnet_port_t *port, tnet_ip_t *ip);
  611. TINYSIP_API int tsip_stack_stop(tsip_stack_handle_t *self);
  612. #define TSIP_STACK_EVENT_RAISE(stack, status_code, reason_phrase, incoming, type) \
  613. TSK_RUNNABLE_ENQUEUE(TSK_RUNNABLE(stack), (const tsip_stack_handle_t*)stack, (short)status_code, (const char*)reason_phrase, (unsigned)incoming, (tsip_event_type_t)type);
  614. TINYSIP_GEXTERN const tsk_object_def_t *tsip_stack_def_t;
  615. TSIP_END_DECLS
  616. #endif /* TINYSIP_TSIP_H */