ccss.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2010, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Call Completion Supplementary Services API
  20. * \author Mark Michelson <mmichelson@digium.com>
  21. */
  22. #ifndef _ASTERISK_CCSS_H
  23. #define _ASTERISK_CCSS_H
  24. #include "asterisk.h"
  25. #include "asterisk/linkedlists.h"
  26. #include "asterisk/devicestate.h"
  27. enum ast_cc_service_type {
  28. /* No Service available/requested */
  29. AST_CC_NONE,
  30. /* Call Completion Busy Subscriber */
  31. AST_CC_CCBS,
  32. /* Call Completion No Response */
  33. AST_CC_CCNR,
  34. /* Call Completion Not Logged In (currently SIP only) */
  35. AST_CC_CCNL,
  36. };
  37. /*!
  38. * \since 1.8
  39. * \brief The various possibilities for cc_agent_policy values
  40. */
  41. enum ast_cc_agent_policies {
  42. /*! Never offer CCSS to the caller */
  43. AST_CC_AGENT_NEVER,
  44. /*! Offer CCSS using native signaling */
  45. AST_CC_AGENT_NATIVE,
  46. /*! Use generic agent for caller */
  47. AST_CC_AGENT_GENERIC,
  48. };
  49. /*!
  50. * \brief agent flags that can alter core behavior
  51. */
  52. enum ast_cc_agent_flags {
  53. /* Some agent types allow for a caller to
  54. * request CC without reaching the CC_CALLER_OFFERED
  55. * state. In other words, the caller can request
  56. * CC while he is still on the phone from the failed
  57. * call. The generic agent is an agent which allows
  58. * for this behavior.
  59. */
  60. AST_CC_AGENT_SKIP_OFFER = (1 << 0),
  61. };
  62. /*!
  63. * \since 1.8
  64. * \brief The various possibilities for cc_monitor_policy values
  65. */
  66. enum ast_cc_monitor_policies {
  67. /*! Never accept CCSS offers from callee */
  68. AST_CC_MONITOR_NEVER,
  69. /* CCSS only available if callee offers it through signaling */
  70. AST_CC_MONITOR_NATIVE,
  71. /*! Always use CCSS generic monitor for callee
  72. * Note that if callee offers CCSS natively, we still
  73. * will use a generic CCSS monitor if this is set
  74. */
  75. AST_CC_MONITOR_GENERIC,
  76. /*! Accept native CCSS offers, but if no offer is present,
  77. * use a generic CCSS monitor
  78. */
  79. AST_CC_MONITOR_ALWAYS,
  80. };
  81. /* Forward declaration. Struct is in main/ccss.c */
  82. struct ast_cc_config_params;
  83. /*!
  84. * \since 1.8
  85. * \brief Queue an AST_CONTROL_CC frame
  86. *
  87. * \note
  88. * Since this function calls ast_queue_frame, the channel will be
  89. * locked during the course of this function.
  90. *
  91. * \param chan The channel onto which to queue the frame
  92. * \param monitor_type The type of monitor to use when CC is requested
  93. * \param dialstring The dial string used to call the device
  94. * \param service The type of CC service the device is willing to offer
  95. * \param private_data If a native monitor is being used, and some channel-driver-specific private
  96. * data has been allocated, then this parameter should contain a pointer to that data. If using a generic
  97. * monitor, this parameter should remain NULL. Note that if this function should fail at some point,
  98. * it is the responsibility of the caller to free the private data upon return.
  99. * \retval 0 Success
  100. * \retval -1 Error
  101. */
  102. int ast_queue_cc_frame(struct ast_channel *chan, const char * const monitor_type,
  103. const char * const dialstring, enum ast_cc_service_type service, void *private_data);
  104. /*!
  105. * \brief Allocate and initialize an ast_cc_config_params structure
  106. *
  107. * \note
  108. * Reasonable default values are chosen for the parameters upon allocation.
  109. *
  110. * \retval NULL Unable to allocate the structure
  111. * \retval non-NULL A pointer to the newly allocated and initialized structure
  112. */
  113. struct ast_cc_config_params *__ast_cc_config_params_init(const char *file, int line, const char *function);
  114. /*!
  115. * \brief Allocate and initialize an ast_cc_config_params structure
  116. *
  117. * \note
  118. * Reasonable default values are chosen for the parameters upon allocation.
  119. *
  120. * \retval NULL Unable to allocate the structure
  121. * \retval non-NULL A pointer to the newly allocated and initialized structure
  122. */
  123. #define ast_cc_config_params_init() __ast_cc_config_params_init(__FILE__, __LINE__, __PRETTY_FUNCTION__)
  124. /*!
  125. * \brief Free memory from CCSS configuration params
  126. *
  127. * \note
  128. * Just a call to ast_free for now...
  129. *
  130. * \param params Pointer to structure whose memory we need to free
  131. * \retval void
  132. */
  133. void ast_cc_config_params_destroy(struct ast_cc_config_params *params);
  134. /*!
  135. * \brief set a CCSS configuration parameter, given its name
  136. *
  137. * \note
  138. * Useful when parsing config files when used in conjunction
  139. * with ast_ccss_is_cc_config_param.
  140. *
  141. * \param params The parameter structure to set the value on
  142. * \param name The name of the cc parameter
  143. * \param value The value of the parameter
  144. * \retval 0 Success
  145. * \retval -1 Failure
  146. */
  147. int ast_cc_set_param(struct ast_cc_config_params *params, const char * const name,
  148. const char * value);
  149. /*!
  150. * \brief get a CCSS configuration parameter, given its name
  151. *
  152. * \note
  153. * Useful when reading input as a string, like from dialplan or
  154. * manager.
  155. *
  156. * \param params The CCSS configuration from which to get the value
  157. * \param name The name of the CCSS parameter we want
  158. * \param buf A preallocated buffer to hold the value
  159. * \param buf_len The size of buf
  160. * \retval 0 Success
  161. * \retval -1 Failure
  162. */
  163. int ast_cc_get_param(struct ast_cc_config_params *params, const char * const name,
  164. char *buf, size_t buf_len);
  165. /*!
  166. * \since 1.8
  167. * \brief Is this a CCSS configuration parameter?
  168. * \param name Name of configuration option being parsed.
  169. * \retval 1 Yes, this is a CCSS configuration parameter.
  170. * \retval 0 No, this is not a CCSS configuration parameter.
  171. */
  172. int ast_cc_is_config_param(const char * const name);
  173. /*!
  174. * \since 1.8
  175. * \brief Set the specified CC config params to default values.
  176. *
  177. * \details
  178. * This is just like ast_cc_copy_config_params() and could be used in place
  179. * of it if you need to set the config params to defaults instead.
  180. * You are simply "copying" defaults into the destination.
  181. *
  182. * \param params CC config params to set to default values.
  183. *
  184. * \return Nothing
  185. */
  186. void ast_cc_default_config_params(struct ast_cc_config_params *params);
  187. /*!
  188. * \since 1.8
  189. * \brief copy CCSS configuration parameters from one structure to another
  190. *
  191. * \details
  192. * For now, this is a simple memcpy, but this function is necessary since
  193. * the size of an ast_cc_config_params structure is unknown outside of
  194. * main/ccss.c. Also, this allows for easier expansion of the function in
  195. * case it becomes more complex than just a memcpy.
  196. *
  197. * \param src The structure from which data is copied
  198. * \param dest The structure to which data is copied
  199. *
  200. * \return Nothing
  201. */
  202. void ast_cc_copy_config_params(struct ast_cc_config_params *dest, const struct ast_cc_config_params *src);
  203. /*!
  204. * \since 1.8
  205. * \brief Get the cc_agent_policy
  206. * \param config The configuration to retrieve the policy from
  207. * \return The current cc_agent_policy for this configuration
  208. */
  209. enum ast_cc_agent_policies ast_get_cc_agent_policy(struct ast_cc_config_params *config);
  210. /*!
  211. * \since 1.8
  212. * \brief Set the cc_agent_policy
  213. * \param config The configuration to set the cc_agent_policy on
  214. * \param value The new cc_agent_policy we want to change to
  215. * \retval 0 Success
  216. * \retval -1 Failure (likely due to bad input)
  217. */
  218. int ast_set_cc_agent_policy(struct ast_cc_config_params *config, enum ast_cc_agent_policies value);
  219. /*!
  220. * \since 1.8
  221. * \brief Get the cc_monitor_policy
  222. * \param config The configuration to retrieve the cc_monitor_policy from
  223. * \return The cc_monitor_policy retrieved from the configuration
  224. */
  225. enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config);
  226. /*!
  227. * \since 1.8
  228. * \brief Set the cc_monitor_policy
  229. * \param config The configuration to set the cc_monitor_policy on
  230. * \param value The new cc_monitor_policy we want to change to
  231. * \retval 0 Success
  232. * \retval -1 Failure (likely due to bad input)
  233. */
  234. int ast_set_cc_monitor_policy(struct ast_cc_config_params *config, enum ast_cc_monitor_policies value);
  235. /*!
  236. * \since 1.8
  237. * \brief Get the cc_offer_timer
  238. * \param config The configuration to retrieve the cc_offer_timer from
  239. * \return The cc_offer_timer from this configuration
  240. */
  241. unsigned int ast_get_cc_offer_timer(struct ast_cc_config_params *config);
  242. /*!
  243. * \since 1.8
  244. * \brief Set the cc_offer_timer
  245. * \param config The configuration to set the cc_offer_timer on
  246. * \param value The new cc_offer_timer we want to change to
  247. * \retval void
  248. */
  249. void ast_set_cc_offer_timer(struct ast_cc_config_params *config, unsigned int value);
  250. /*!
  251. * \since 1.8
  252. * \brief Get the ccnr_available_timer
  253. * \param config The configuration to retrieve the ccnr_available_timer from
  254. * \return The ccnr_available_timer from this configuration
  255. */
  256. unsigned int ast_get_ccnr_available_timer(struct ast_cc_config_params *config);
  257. /*!
  258. * \since 1.8
  259. * \brief Set the ccnr_available_timer
  260. * \param config The configuration to set the ccnr_available_timer on
  261. * \param value The new ccnr_available_timer we want to change to
  262. * \retval void
  263. */
  264. void ast_set_ccnr_available_timer(struct ast_cc_config_params *config, unsigned int value);
  265. /*!
  266. * \since 1.8
  267. * \brief Get the cc_recall_timer
  268. * \param config The configuration to retrieve the cc_recall_timer from
  269. * \return The cc_recall_timer from this configuration
  270. */
  271. unsigned int ast_get_cc_recall_timer(struct ast_cc_config_params *config);
  272. /*!
  273. * \since 1.8
  274. * \brief Set the cc_recall_timer
  275. * \param config The configuration to set the cc_recall_timer on
  276. * \param value The new cc_recall_timer we want to change to
  277. * \retval void
  278. */
  279. void ast_set_cc_recall_timer(struct ast_cc_config_params *config, unsigned int value);
  280. /*!
  281. * \since 1.8
  282. * \brief Get the ccbs_available_timer
  283. * \param config The configuration to retrieve the ccbs_available_timer from
  284. * \return The ccbs_available_timer from this configuration
  285. */
  286. unsigned int ast_get_ccbs_available_timer(struct ast_cc_config_params *config);
  287. /*!
  288. * \since 1.8
  289. * \brief Set the ccbs_available_timer
  290. * \param config The configuration to set the ccbs_available_timer on
  291. * \param value The new ccbs_available_timer we want to change to
  292. * \retval void
  293. */
  294. void ast_set_ccbs_available_timer(struct ast_cc_config_params *config, unsigned int value);
  295. /*!
  296. * \since 1.8
  297. * \brief Get the cc_agent_dialstring
  298. * \param config The configuration to retrieve the cc_agent_dialstring from
  299. * \return The cc_agent_dialstring from this configuration
  300. */
  301. const char *ast_get_cc_agent_dialstring(struct ast_cc_config_params *config);
  302. /*!
  303. * \since 1.8
  304. * \brief Set the cc_agent_dialstring
  305. * \param config The configuration to set the cc_agent_dialstring on
  306. * \param value The new cc_agent_dialstring we want to change to
  307. * \retval void
  308. */
  309. void ast_set_cc_agent_dialstring(struct ast_cc_config_params *config, const char *const value);
  310. /*!
  311. * \since 1.8
  312. * \brief Get the cc_max_agents
  313. * \param config The configuration to retrieve the cc_max_agents from
  314. * \return The cc_max_agents from this configuration
  315. */
  316. unsigned int ast_get_cc_max_agents(struct ast_cc_config_params *config);
  317. /*!
  318. * \since 1.8
  319. * \brief Set the cc_max_agents
  320. * \param config The configuration to set the cc_max_agents on
  321. * \param value The new cc_max_agents we want to change to
  322. * \retval void
  323. */
  324. void ast_set_cc_max_agents(struct ast_cc_config_params *config, unsigned int value);
  325. /*!
  326. * \since 1.8
  327. * \brief Get the cc_max_monitors
  328. * \param config The configuration to retrieve the cc_max_monitors from
  329. * \return The cc_max_monitors from this configuration
  330. */
  331. unsigned int ast_get_cc_max_monitors(struct ast_cc_config_params *config);
  332. /*!
  333. * \since 1.8
  334. * \brief Set the cc_max_monitors
  335. * \param config The configuration to set the cc_max_monitors on
  336. * \param value The new cc_max_monitors we want to change to
  337. * \retval void
  338. */
  339. void ast_set_cc_max_monitors(struct ast_cc_config_params *config, unsigned int value);
  340. /*!
  341. * \since 1.8
  342. * \brief Get the name of the callback_macro
  343. * \param config The configuration to retrieve the callback_macro from
  344. * \return The callback_macro name
  345. */
  346. const char *ast_get_cc_callback_macro(struct ast_cc_config_params *config);
  347. /*!
  348. * \since 1.8
  349. * \brief Set the callback_macro name
  350. * \param config The configuration to set the callback_macro on
  351. * \param value The new callback macro we want to change to
  352. * \retval void
  353. */
  354. void ast_set_cc_callback_macro(struct ast_cc_config_params *config, const char * const value);
  355. /*!
  356. * \since 11
  357. * \brief Get the name of the callback subroutine
  358. * \param config The configuration to retrieve the callback_sub from
  359. * \return The callback_sub name
  360. */
  361. const char *ast_get_cc_callback_sub(struct ast_cc_config_params *config);
  362. /*!
  363. * \since 11
  364. * \brief Set the callback subroutine name
  365. * \param config The configuration to set the callback_sub on
  366. * \param value The new callback subroutine we want to change to
  367. * \retval void
  368. */
  369. void ast_set_cc_callback_sub(struct ast_cc_config_params *config, const char * const value);
  370. /* END CONFIGURATION FUNCTIONS */
  371. /* BEGIN AGENT/MONITOR REGISTRATION API */
  372. struct ast_cc_monitor_callbacks;
  373. /*!
  374. * \since 1.8
  375. * \brief Register a set of monitor callbacks with the core
  376. *
  377. * \details
  378. * This is made so that at monitor creation time, the proper callbacks
  379. * may be installed and the proper .init callback may be called for the
  380. * monitor to establish private data.
  381. *
  382. * \param callbacks The callbacks used by the monitor implementation
  383. * \retval 0 Successfully registered
  384. * \retval -1 Failure to register
  385. */
  386. int ast_cc_monitor_register(const struct ast_cc_monitor_callbacks *callbacks);
  387. /*!
  388. * \since 1.8
  389. * \brief Unregister a set of monitor callbacks with the core
  390. *
  391. * \details
  392. * If a module which makes use of a CC monitor is unloaded, then it may
  393. * unregister its monitor callbacks with the core.
  394. *
  395. * \param callbacks The callbacks used by the monitor implementation
  396. * \retval 0 Successfully unregistered
  397. * \retval -1 Failure to unregister
  398. */
  399. void ast_cc_monitor_unregister(const struct ast_cc_monitor_callbacks *callbacks);
  400. struct ast_cc_agent_callbacks;
  401. /*!
  402. * \since 1.8
  403. * \brief Register a set of agent callbacks with the core
  404. *
  405. * \details
  406. * This is made so that at agent creation time, the proper callbacks
  407. * may be installed and the proper .init callback may be called for the
  408. * monitor to establish private data.
  409. *
  410. * \param callbacks The callbacks used by the agent implementation
  411. * \retval 0 Successfully registered
  412. * \retval -1 Failure to register
  413. */
  414. int ast_cc_agent_register(const struct ast_cc_agent_callbacks *callbacks);
  415. /*!
  416. * \since 1.8
  417. * \brief Unregister a set of agent callbacks with the core
  418. *
  419. * \details
  420. * If a module which makes use of a CC agent is unloaded, then it may
  421. * unregister its agent callbacks with the core.
  422. *
  423. * \param callbacks The callbacks used by the agent implementation
  424. * \retval 0 Successfully unregistered
  425. * \retval -1 Failure to unregister
  426. */
  427. void ast_cc_agent_unregister(const struct ast_cc_agent_callbacks *callbacks);
  428. /* END AGENT/MONITOR REGISTRATION API */
  429. /* BEGIN SECTION ON MONITORS AND MONITOR CALLBACKS */
  430. /*!
  431. * It is recommended that monitors use a pointer to
  432. * an ast_cc_monitor_callbacks::type when creating
  433. * an AST_CONTROL_CC frame. Since the generic monitor
  434. * callbacks are opaque and channel drivers will wish
  435. * to use that, this string is made globally available
  436. * for all to use
  437. */
  438. #define AST_CC_GENERIC_MONITOR_TYPE "generic"
  439. /*!
  440. * Used to determine which type
  441. * of monitor an ast_cc_device_monitor
  442. * is.
  443. */
  444. enum ast_cc_monitor_class {
  445. AST_CC_DEVICE_MONITOR,
  446. AST_CC_EXTENSION_MONITOR,
  447. };
  448. /*!
  449. * \internal
  450. * \brief An item in a CC interface tree.
  451. *
  452. * These are the individual items in an interface tree.
  453. * The key difference between this structure and the ast_cc_interface
  454. * is that this structure contains data which is intrinsic to the item's
  455. * placement in the tree, such as who its parent is.
  456. */
  457. struct ast_cc_monitor {
  458. /*!
  459. * Information regarding the interface.
  460. */
  461. struct ast_cc_interface *interface;
  462. /*!
  463. * Every interface has an id that uniquely identifies it. It is
  464. * formed by incrementing a counter.
  465. */
  466. unsigned int id;
  467. /*!
  468. * The ID of this monitor's parent. If this monitor is at the
  469. * top of the tree, then his parent will be 0.
  470. */
  471. unsigned int parent_id;
  472. /*!
  473. * The instance of the CC core to which this monitor belongs
  474. */
  475. int core_id;
  476. /*!
  477. * The type of call completion service offered by a device.
  478. */
  479. enum ast_cc_service_type service_offered;
  480. /*!
  481. * \brief Name that should be used to recall specified interface
  482. *
  483. * \details
  484. * When issuing a CC recall, some technologies will require
  485. * that a name other than the device name is dialed. For instance,
  486. * with SIP, a specific URI will be used which chan_sip will be able
  487. * to recognize as being a CC recall. Similarly, ISDN will need a specific
  488. * dial string to know that the call is a recall.
  489. */
  490. char *dialstring;
  491. /*!
  492. * The ID of the available timer used by the current monitor
  493. */
  494. int available_timer_id;
  495. /*!
  496. * Monitor callbacks
  497. */
  498. const struct ast_cc_monitor_callbacks *callbacks;
  499. /*!
  500. * \brief Data that is private to a monitor technology
  501. *
  502. * Most channel drivers that implement CC monitors will have to
  503. * allocate data that the CC core does not care about but which
  504. * is vital to the operation of the monitor. This data is stored
  505. * in this pointer so that the channel driver may use it as
  506. * needed
  507. */
  508. void *private_data;
  509. AST_LIST_ENTRY(ast_cc_monitor) next;
  510. };
  511. /*!
  512. * \brief Callbacks defined by CC monitors
  513. *
  514. * \note
  515. * Every callback is called with the list of monitors locked. There
  516. * are several public API calls that also will try to lock this lock.
  517. * These public functions have a note in their doxygen stating so.
  518. * As such, pay attention to the lock order you establish in these callbacks
  519. * to ensure that you do not violate the lock order when calling
  520. * the functions in this file with lock order notices.
  521. */
  522. struct ast_cc_monitor_callbacks {
  523. /*!
  524. * \brief Type of monitor the callbacks belong to.
  525. *
  526. * \note
  527. * Examples include "generic" and "SIP"
  528. */
  529. const char *type;
  530. /*!
  531. * \brief Request CCSS.
  532. *
  533. * \param monitor CC core monitor control.
  534. * \param available_timer_id The scheduler ID for the available timer.
  535. * Will never be NULL for a device monitor.
  536. *
  537. * \details
  538. * Perform whatever steps are necessary in order to request CC.
  539. * In addition, the monitor implementation is responsible for
  540. * starting the available timer in this callback.
  541. *
  542. * \retval 0 on success
  543. * \retval -1 on failure.
  544. */
  545. int (*request_cc)(struct ast_cc_monitor *monitor, int *available_timer_id);
  546. /*!
  547. * \brief Suspend monitoring.
  548. *
  549. * \param monitor CC core monitor control.
  550. *
  551. * \details
  552. * Implementers must perform the necessary steps to suspend
  553. * monitoring.
  554. *
  555. * \retval 0 on success
  556. * \retval -1 on failure.
  557. */
  558. int (*suspend)(struct ast_cc_monitor *monitor);
  559. /*!
  560. * \brief Status response to an ast_cc_monitor_status_request().
  561. *
  562. * \param monitor CC core monitor control.
  563. * \param devstate Current status of a Party A device.
  564. *
  565. * \details
  566. * Alert a monitor as to the status of the agent for which
  567. * the monitor had previously requested a status request.
  568. *
  569. * \note Zero or more responses may come as a result.
  570. *
  571. * \retval 0 on success
  572. * \retval -1 on failure.
  573. */
  574. int (*status_response)(struct ast_cc_monitor *monitor, enum ast_device_state devstate);
  575. /*!
  576. * \brief Unsuspend monitoring.
  577. *
  578. * \param monitor CC core monitor control.
  579. *
  580. * \details
  581. * Perform the necessary steps to unsuspend monitoring.
  582. *
  583. * \retval 0 on success
  584. * \retval -1 on failure.
  585. */
  586. int (*unsuspend)(struct ast_cc_monitor *monitor);
  587. /*!
  588. * \brief Cancel the running available timer.
  589. *
  590. * \param monitor CC core monitor control.
  591. * \param sched_id Available timer scheduler id to cancel.
  592. * Will never be NULL for a device monitor.
  593. *
  594. * \details
  595. * In most cases, this function will likely consist of just a
  596. * call to AST_SCHED_DEL. It might have been possible to do this
  597. * within the core, but unfortunately the mixture of sched_thread
  598. * and sched usage in Asterisk prevents such usage.
  599. *
  600. * \retval 0 on success
  601. * \retval -1 on failure.
  602. */
  603. int (*cancel_available_timer)(struct ast_cc_monitor *monitor, int *sched_id);
  604. /*!
  605. * \brief Destroy private data on the monitor.
  606. *
  607. * \param private_data The private data pointer from the monitor.
  608. *
  609. * \details
  610. * Implementers of this callback are responsible for destroying
  611. * all heap-allocated data in the monitor's private_data pointer, including
  612. * the private_data itself.
  613. */
  614. void (*destructor)(void *private_data);
  615. };
  616. /*!
  617. * \since 1.8
  618. * \brief Scheduler callback for available timer expiration
  619. *
  620. * \note
  621. * When arming the available timer from within a device monitor, you MUST
  622. * use this function as the callback for the scheduler.
  623. *
  624. * \param data A reference to the CC monitor on which the timer was running.
  625. */
  626. int ast_cc_available_timer_expire(const void *data);
  627. /* END SECTION ON MONITORS AND MONITOR CALLBACKS */
  628. /* BEGIN API FOR IN-CALL CC HANDLING */
  629. /*!
  630. * \since 1.8
  631. *
  632. * \brief Mark the channel to ignore further CC activity.
  633. *
  634. * \details
  635. * When a CC-capable application, such as Dial, has finished
  636. * with all CC processing for a channel and knows that any further
  637. * CC processing should be ignored, this function should be called.
  638. *
  639. * \param chan The channel for which further CC processing should be ignored.
  640. * \retval void
  641. */
  642. void ast_ignore_cc(struct ast_channel *chan);
  643. /*!
  644. * \since 1.8
  645. *
  646. * \brief Properly react to a CC control frame.
  647. *
  648. * \details
  649. * When a CC-capable application, such as Dial, receives a frame
  650. * of type AST_CONTROL_CC, then it may call this function in order
  651. * to have the device which sent the frame added to the tree of interfaces
  652. * which is kept on the inbound channel.
  653. *
  654. * \param inbound The inbound channel
  655. * \param outbound The outbound channel (The one from which the CC frame was read)
  656. * \param frame_data The ast_frame's data.ptr field.
  657. * \retval void
  658. */
  659. void ast_handle_cc_control_frame(struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data);
  660. /*!
  661. * \since 1.8
  662. *
  663. * \brief Start the CC process on a call.
  664. *
  665. * \details
  666. * Whenever a CC-capable application, such as Dial, wishes to
  667. * engage in CC activity, it initiates the process by calling this
  668. * function. If the CC core should discover that a previous application
  669. * has called ast_ignore_cc on this channel or a "parent" channel, then
  670. * the value of the ignore_cc integer passed in will be set nonzero.
  671. *
  672. * The ignore_cc parameter is a convenience parameter. It can save an
  673. * application the trouble of trying to call CC APIs when it knows that
  674. * it should just ignore further attempts at CC actions.
  675. *
  676. * \param chan The inbound channel calling the CC-capable application.
  677. * \param[out] ignore_cc Will be set non-zero if no further CC actions need to be taken
  678. * \retval 0 Success
  679. * \retval -1 Failure
  680. */
  681. int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc);
  682. /*!
  683. * \since 1.8
  684. *
  685. * \brief Add a child dialstring to an extension monitor
  686. *
  687. * Whenever we request a channel, the parent extension monitor needs
  688. * to store the dialstring of the device requested. The reason is so
  689. * that we can call the device back during the recall even if we are
  690. * not monitoring the device.
  691. *
  692. * \param incoming The caller's channel
  693. * \param dialstring The dialstring used when requesting the outbound channel
  694. * \param device_name The device name associated with the requested outbound channel
  695. * \retval void
  696. */
  697. void ast_cc_extension_monitor_add_dialstring(struct ast_channel *incoming, const char * const dialstring, const char * const device_name);
  698. /*!
  699. * \since 1.8
  700. * \brief Check if the incoming CC request is within the bounds
  701. * set by the cc_max_requests configuration option
  702. *
  703. * \details
  704. * It is recommended that an entity which receives an incoming
  705. * CC request calls this function before calling
  706. * ast_cc_agent_accept_request. This way, immediate feedback can be
  707. * given to the caller about why his request was rejected.
  708. *
  709. * If this is not called and a state change to CC_CALLER_REQUESTED
  710. * is made, then the core will still not allow for the request
  711. * to succeed. However, if done this way, it may not be obvious
  712. * to the requestor why the request failed.
  713. *
  714. * \retval 0 Not within the limits. Fail.
  715. * \retval non-zero Within the limits. Success.
  716. */
  717. int ast_cc_request_is_within_limits(void);
  718. /*!
  719. * \since 1.8
  720. * \brief Get the core id for the current call
  721. *
  722. * \details
  723. * The main use of this function is for channel drivers
  724. * who queue an AST_CONTROL_CC frame. A channel driver may
  725. * call this function in order to get the core_id for what
  726. * may become a CC request. This way, when monitor functions
  727. * are called which use a core_id as a means of identification,
  728. * the channel driver will have saved this information.
  729. *
  730. * The channel given to this function may be an inbound or outbound
  731. * channel. Both will have the necessary info on it.
  732. *
  733. * \param chan The channel from which to get the core_id.
  734. * \retval core_id on success
  735. * \retval -1 Failure
  736. */
  737. int ast_cc_get_current_core_id(struct ast_channel *chan);
  738. /* END API FOR IN-CALL CC HANDLING */
  739. /*!
  740. * \brief Structure with information about an outbound interface
  741. *
  742. * \details
  743. * This structure is first created when an outbound interface indicates that
  744. * it is capable of accepting a CC request. It is stored in a "tree" on a datastore on
  745. * the caller's channel. Once an agent structure is created, the agent gains
  746. * a reference to the tree of interfaces. If CC is requested, then the
  747. * interface tree on the agent is converted into a tree of monitors. Each
  748. * monitor will contain a pointer to an individual ast_cc_interface. Finally,
  749. * the tree of interfaces is also present on a second datastore during a
  750. * CC recall so that the CC_INTERFACES channel variable may be properly
  751. * populated.
  752. */
  753. struct ast_cc_interface {
  754. /* What class of monitor is being offered here
  755. */
  756. enum ast_cc_monitor_class monitor_class;
  757. /*!
  758. * \brief The type of monitor that should be used for this interface
  759. *
  760. * \details
  761. * This will be something like "extension" "generic" or "SIP".
  762. * This should point to a static const char *, so there is
  763. * no reason to make a new copy.
  764. */
  765. const char *monitor_type;
  766. /*!
  767. * The configuration parameters used for this interface
  768. */
  769. struct ast_cc_config_params *config_params;
  770. /* The name of the interface/extension. local channels will
  771. * have 'exten@context' for a name. Other channel types will
  772. * have 'tech/device' for a name.
  773. */
  774. char device_name[1];
  775. };
  776. /* BEGIN STRUCTURES FOR AGENTS */
  777. struct ast_cc_agent {
  778. /*!
  779. * Which instance of the core state machine does this
  780. * agent pertain to?
  781. */
  782. unsigned int core_id;
  783. /*!
  784. * Callback functions needed for specific agent
  785. * implementations
  786. */
  787. const struct ast_cc_agent_callbacks *callbacks;
  788. /*!
  789. * Configuration parameters that affect this
  790. * agent's operation.
  791. */
  792. struct ast_cc_config_params *cc_params;
  793. /*!
  794. * \brief Flags for agent operation
  795. *
  796. * \details
  797. * There are some attributes of certain agent types
  798. * that can alter the behavior of certain CC functions.
  799. * For a list of these flags, see the ast_cc_agent_flags
  800. * enum
  801. */
  802. unsigned int flags;
  803. /*! Data specific to agent implementation */
  804. void *private_data;
  805. /*! The name of the device which this agent
  806. * represents/communicates with
  807. */
  808. char device_name[1];
  809. };
  810. enum ast_cc_agent_response_reason {
  811. /*! CC request accepted */
  812. AST_CC_AGENT_RESPONSE_SUCCESS,
  813. /*! CC request not allowed at this time. Invalid state transition. */
  814. AST_CC_AGENT_RESPONSE_FAILURE_INVALID,
  815. /*! Too many CC requests in the system. */
  816. AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY,
  817. };
  818. struct ast_cc_agent_callbacks {
  819. /*!
  820. * \brief Type of agent the callbacks belong to.
  821. *
  822. * \note
  823. * Examples are "SIP" "ISDN" and "generic"
  824. */
  825. const char *type;
  826. /*!
  827. * \brief CC agent initialization.
  828. *
  829. * \param agent CC core agent control.
  830. * \param chan Original channel the agent will attempt to recall.
  831. *
  832. * \details
  833. * This callback is called when the CC core
  834. * is initialized. Agents should allocate
  835. * any private data necessary for the
  836. * call and assign it to the private_data
  837. * on the agent. Additionally, if any ast_cc_agent_flags
  838. * are pertinent to the specific agent type, they should
  839. * be set in this function as well.
  840. *
  841. * \retval 0 on success.
  842. * \retval -1 on error.
  843. */
  844. int (*init)(struct ast_cc_agent *agent, struct ast_channel *chan);
  845. /*!
  846. * \brief Start the offer timer.
  847. *
  848. * \param agent CC core agent control.
  849. *
  850. * \details
  851. * This is called by the core when the caller hangs up after
  852. * a call for which CC may be requested. The agent should
  853. * begin the timer as configured.
  854. *
  855. * The primary reason why this functionality is left to
  856. * the specific agent implementations is due to the differing
  857. * use of schedulers throughout the code. Some channel drivers
  858. * may already have a scheduler context they wish to use, and
  859. * amongst those, some may use the ast_sched API while others
  860. * may use the ast_sched_thread API, which are incompatible.
  861. *
  862. * \retval 0 on success.
  863. * \retval -1 on error.
  864. */
  865. int (*start_offer_timer)(struct ast_cc_agent *agent);
  866. /*!
  867. * \brief Stop the offer timer.
  868. *
  869. * \param agent CC core agent control.
  870. *
  871. * \details
  872. * This callback is called by the CC core when the caller
  873. * has requested CC.
  874. *
  875. * \retval 0 on success.
  876. * \retval -1 on error.
  877. */
  878. int (*stop_offer_timer)(struct ast_cc_agent *agent);
  879. /*!
  880. * \brief Respond to a CC request.
  881. *
  882. * \param agent CC core agent control.
  883. * \param reason CC request response status.
  884. *
  885. * \details
  886. * When the core receives knowledge that a called
  887. * party has accepted a CC request, it will call
  888. * this callback. The core may also call this
  889. * if there is some error when attempting to process
  890. * the incoming CC request.
  891. *
  892. * The duty of this is to issue a propper response to a
  893. * CC request from the caller by acknowledging receipt
  894. * of that request or rejecting it.
  895. */
  896. void (*respond)(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason);
  897. /*!
  898. * \brief Request the status of the agent's device.
  899. *
  900. * \param agent CC core agent control.
  901. *
  902. * \details
  903. * Asynchronous request for the status of any caller
  904. * which may be a valid caller for the CC transaction.
  905. * Status responses should be made using the
  906. * ast_cc_status_response function.
  907. *
  908. * \retval 0 on success.
  909. * \retval -1 on error.
  910. */
  911. int (*status_request)(struct ast_cc_agent *agent);
  912. /*!
  913. * \brief Request for an agent's phone to stop ringing.
  914. *
  915. * \param agent CC core agent control.
  916. *
  917. * \details
  918. * The usefulness of this is quite limited. The only specific
  919. * known case for this is if Asterisk requests CC over an ISDN
  920. * PTMP link as the TE side. If other phones are in the same
  921. * recall group as the Asterisk server, and one of those phones
  922. * picks up the recall notice, then Asterisk will receive a
  923. * "stop ringing" notification from the NT side of the PTMP
  924. * link. This indication needs to be passed to the phone
  925. * on the other side of the Asterisk server which originally
  926. * placed the call so that it will stop ringing. Since the
  927. * phone may be of any type, it is necessary to have a callback
  928. * that the core can know about.
  929. *
  930. * \retval 0 on success.
  931. * \retval -1 on error.
  932. */
  933. int (*stop_ringing)(struct ast_cc_agent *agent);
  934. /*!
  935. * \brief Let the caller know that the callee has become free
  936. * but that the caller cannot attempt to call back because
  937. * he is either busy or there is congestion on his line.
  938. *
  939. * \param agent CC core agent control.
  940. *
  941. * \details
  942. * This is something that really only affects a scenario where
  943. * a phone places a call over ISDN PTMP to Asterisk, who then
  944. * connects over PTMP again to the ISDN network. For most agent
  945. * types, there is no need to implement this callback at all
  946. * because they don't really need to actually do anything in
  947. * this situation. If you're having trouble understanding what
  948. * the purpose of this callback is, then you can be safe simply
  949. * not implementing it.
  950. *
  951. * \retval 0 on success.
  952. * \retval -1 on error.
  953. */
  954. int (*party_b_free)(struct ast_cc_agent *agent);
  955. /*!
  956. * \brief Begin monitoring a busy device.
  957. *
  958. * \param agent CC core agent control.
  959. *
  960. * \details
  961. * The core will call this callback if the callee becomes
  962. * available but the caller has reported that he is busy.
  963. * The agent should begin monitoring the caller's device.
  964. * When the caller becomes available again, the agent should
  965. * call ast_cc_agent_caller_available.
  966. *
  967. * \retval 0 on success.
  968. * \retval -1 on error.
  969. */
  970. int (*start_monitoring)(struct ast_cc_agent *agent);
  971. /*!
  972. * \brief Alert the caller that it is time to try recalling.
  973. *
  974. * \param agent CC core agent control.
  975. *
  976. * \details
  977. * The core will call this function when it receives notice
  978. * that a monitored party has become available.
  979. *
  980. * The agent's job is to send a message to the caller to
  981. * notify it of such a change. If the agent is able to
  982. * discern that the caller is currently unavailable, then
  983. * the agent should react by calling the ast_cc_caller_unavailable
  984. * function.
  985. *
  986. * \retval 0 on success.
  987. * \retval -1 on error.
  988. */
  989. int (*callee_available)(struct ast_cc_agent *agent);
  990. /*!
  991. * \brief Destroy private data on the agent.
  992. *
  993. * \param agent CC core agent control.
  994. *
  995. * \details
  996. * The core will call this function upon completion
  997. * or failure of CC.
  998. *
  999. * \note
  1000. * The agent private_data pointer may be NULL if the agent
  1001. * constructor failed.
  1002. */
  1003. void (*destructor)(struct ast_cc_agent *agent);
  1004. };
  1005. /*!
  1006. * \brief Call a callback on all agents of a specific type
  1007. *
  1008. * \details
  1009. * Since the container of CC core instances is private, and so
  1010. * are the items which the container contains, we have to provide
  1011. * an ao2_callback-like method so that a specific agent may be
  1012. * found or so that an operation can be made on all agents of
  1013. * a particular type. The first three arguments should be familiar
  1014. * to anyone who has used ao2_callback. The final argument is the
  1015. * type of agent you wish to have the callback called on.
  1016. *
  1017. * \note Since agents are refcounted, and this function returns
  1018. * a reference to the agent, it is imperative that you decrement
  1019. * the refcount of the agent once you have finished using it.
  1020. *
  1021. * \param flags astobj2 search flags
  1022. * \param function an ao2 callback function to call
  1023. * \param arg the argument to the callback function
  1024. * \param type The type of agents to call the callback on
  1025. */
  1026. struct ast_cc_agent *ast_cc_agent_callback(int flags, ao2_callback_fn *function, void *arg, const char * const type);
  1027. /* END STRUCTURES FOR AGENTS */
  1028. /* BEGIN STATE CHANGE API */
  1029. /*!
  1030. * \since 1.8
  1031. * \brief Offer CC to a caller
  1032. *
  1033. * \details
  1034. * This function is called from ast_hangup if the caller is
  1035. * eligible to be offered call completion service.
  1036. *
  1037. * \param caller_chan The calling channel
  1038. * \retval -1 Error
  1039. * \retval 0 Success
  1040. */
  1041. int ast_cc_offer(struct ast_channel *caller_chan);
  1042. /*!
  1043. * \since 1.8
  1044. * \brief Accept inbound CC request
  1045. *
  1046. * \details
  1047. * When a caller requests CC, this function should be called to let
  1048. * the core know that the request has been accepted.
  1049. *
  1050. * \param core_id core_id of the CC transaction
  1051. * \param debug optional string to print for debugging purposes
  1052. * \retval 0 Success
  1053. * \retval -1 Failure
  1054. */
  1055. int __attribute__((format(printf, 2, 3))) ast_cc_agent_accept_request(int core_id, const char * const debug, ...);
  1056. /*!
  1057. * \since 1.8
  1058. * \brief Indicate that an outbound entity has accepted our CC request
  1059. *
  1060. * \details
  1061. * When we receive confirmation that an outbound device has accepted the
  1062. * CC request we sent it, this function must be called.
  1063. *
  1064. * \param core_id core_id of the CC transaction
  1065. * \param debug optional string to print for debugging purposes
  1066. * \retval 0 Success
  1067. * \retval -1 Failure
  1068. */
  1069. int __attribute__((format(printf, 2, 3))) ast_cc_monitor_request_acked(int core_id, const char * const debug, ...);
  1070. /*!
  1071. * \since 1.8
  1072. * \brief Indicate that the caller is busy
  1073. *
  1074. * \details
  1075. * When the callee makes it known that he is available, the core
  1076. * will let the caller's channel driver know that it may attempt
  1077. * to let the caller know to attempt a recall. If the channel
  1078. * driver can detect, though, that the caller is busy, then
  1079. * the channel driver should call this function to let the CC
  1080. * core know.
  1081. *
  1082. * \param core_id core_id of the CC transaction
  1083. * \param debug optional string to print for debugging purposes
  1084. * \retval 0 Success
  1085. * \retval -1 Failure
  1086. */
  1087. int __attribute__((format(printf, 2, 3))) ast_cc_agent_caller_busy(int core_id, const char * const debug, ...);
  1088. /*!
  1089. * \since 1.8
  1090. * \brief Indicate that a previously unavailable caller has become available
  1091. *
  1092. * \details
  1093. * If a monitor is suspended due to a caller becoming unavailable, then this
  1094. * function should be called to indicate that the caller has become available.
  1095. *
  1096. * \param core_id core_id of the CC transaction
  1097. * \param debug optional string to print for debugging purposes
  1098. * \retval 0 Success
  1099. * \retval -1 Failure
  1100. */
  1101. int __attribute__((format(printf, 2, 3))) ast_cc_agent_caller_available(int core_id, const char * const debug, ...);
  1102. /*!
  1103. * \since 1.8
  1104. * \brief Tell the CC core that a caller is currently recalling
  1105. *
  1106. * \details
  1107. * The main purpose of this is so that the core can alert the monitor
  1108. * to stop its available timer since the caller has begun its recall
  1109. * phase.
  1110. *
  1111. * \param core_id core_id of the CC transaction
  1112. * \param debug optional string to print for debugging purposes
  1113. * \retval 0 Success
  1114. * \retval -1 Failure
  1115. */
  1116. int __attribute__((format(printf, 2, 3))) ast_cc_agent_recalling(int core_id, const char * const debug, ...);
  1117. /*!
  1118. * \since 1.8
  1119. * \brief Indicate recall has been acknowledged
  1120. *
  1121. * \details
  1122. * When we receive confirmation that an endpoint has responded to our
  1123. * CC recall, we call this function.
  1124. *
  1125. * \param chan The inbound channel making the CC recall
  1126. * \param debug optional string to print for debugging purposes
  1127. * \retval 0 Success
  1128. * \retval -1 Failure
  1129. */
  1130. int __attribute__((format(printf, 2, 3))) ast_cc_completed(struct ast_channel *chan, const char * const debug, ...);
  1131. /*!
  1132. * \since 1.8
  1133. * \brief Indicate failure has occurred
  1134. *
  1135. * \details
  1136. * If at any point a failure occurs, this is the function to call
  1137. * so that the core can initiate cleanup procedures.
  1138. *
  1139. * \param core_id core_id of the CC transaction
  1140. * \param debug optional string to print for debugging purposes
  1141. * \retval 0 Success
  1142. * \retval -1 Failure
  1143. */
  1144. int __attribute__((format(printf, 2, 3))) ast_cc_failed(int core_id, const char * const debug, ...);
  1145. /*!
  1146. * \since 1.8
  1147. * \brief Indicate that a failure has occurred on a specific monitor
  1148. *
  1149. * \details
  1150. * If a monitor should detect that a failure has occurred when communicating
  1151. * with its endpoint, then ast_cc_monitor_failed should be called. The big
  1152. * difference between ast_cc_monitor_failed and ast_cc_failed is that ast_cc_failed
  1153. * indicates a global failure for a CC transaction, where as ast_cc_monitor_failed
  1154. * is localized to a particular monitor. When ast_cc_failed is called, the entire
  1155. * CC transaction is torn down. When ast_cc_monitor_failed is called, only the
  1156. * monitor on which the failure occurred is pruned from the tree of monitors.
  1157. *
  1158. * If there are no more devices left to monitor when this function is called,
  1159. * then the core will fail the CC transaction globally.
  1160. *
  1161. * \param core_id The core ID for the CC transaction
  1162. * \param monitor_name The name of the monitor on which the failure occurred
  1163. * \param debug A debug message to print to the CC log
  1164. * \return void
  1165. */
  1166. int __attribute__((format(printf, 3, 4))) ast_cc_monitor_failed(int core_id, const char * const monitor_name, const char * const debug, ...);
  1167. /* END STATE CHANGE API */
  1168. /*!
  1169. * The following are all functions which are required due to the unique
  1170. * case where Asterisk is acting as the NT side of an ISDN PTMP
  1171. * connection to the caller and as the TE side of an ISDN PTMP connection
  1172. * to the callee. In such a case, there are several times where the
  1173. * PTMP monitor needs information from the agent in order to formulate
  1174. * the appropriate messages to send.
  1175. */
  1176. /*!
  1177. * \brief Request the status of a caller or callers.
  1178. *
  1179. * \details
  1180. * When an ISDN PTMP monitor senses that the callee has become
  1181. * available, it needs to know the current status of the caller
  1182. * in order to determine the appropriate response to send to
  1183. * the caller. In order to do this, the monitor calls this function.
  1184. * Responses will arrive asynchronously.
  1185. *
  1186. * \note Zero or more responses may come as a result.
  1187. *
  1188. * \param core_id The core ID of the CC transaction
  1189. *
  1190. * \retval 0 Successfully requested status
  1191. * \retval -1 Failed to request status
  1192. */
  1193. int ast_cc_monitor_status_request(int core_id);
  1194. /*!
  1195. * \brief Response with a caller's current status
  1196. *
  1197. * \details
  1198. * When an ISDN PTMP monitor requests the caller's status, the
  1199. * agent must respond to the request using this function. For
  1200. * simplicity it is recommended that the devstate parameter
  1201. * be one of AST_DEVICE_INUSE or AST_DEVICE_NOT_INUSE.
  1202. *
  1203. * \param core_id The core ID of the CC transaction
  1204. * \param devstate The current state of the caller to which the agent pertains
  1205. * \retval 0 Successfully responded with our status
  1206. * \retval -1 Failed to respond with our status
  1207. */
  1208. int ast_cc_agent_status_response(int core_id, enum ast_device_state devstate);
  1209. /*!
  1210. * \brief Alert a caller to stop ringing
  1211. *
  1212. * \details
  1213. * When an ISDN PTMP monitor becomes available, it is assumed
  1214. * that the agent will then cause the caller's phone to ring. In
  1215. * some cases, this is literally what happens. In other cases, it may
  1216. * be that the caller gets a visible indication on his phone that he
  1217. * may attempt to recall the callee. If multiple callers are recalled
  1218. * (since it may be possible to have a group of callers configured as
  1219. * a single party A), and one of those callers picks up his phone, then
  1220. * the ISDN PTMP monitor will alert the other callers to stop ringing.
  1221. * The agent's stop_ringing callback will be called, and it is up to the
  1222. * agent's driver to send an appropriate message to make his caller
  1223. * stop ringing.
  1224. *
  1225. * \param core_id The core ID of the CC transaction
  1226. * \retval 0 Successfully requested for the phone to stop ringing
  1227. * \retval -1 Could not request for the phone to stop ringing
  1228. */
  1229. int ast_cc_monitor_stop_ringing(int core_id);
  1230. /*!
  1231. * \brief Alert a caller that though the callee has become free, the caller
  1232. * himself is not and may not call back.
  1233. *
  1234. * \details
  1235. * When an ISDN PTMP monitor senses that his monitored party has become
  1236. * available, he will request the status of the called party. If he determines
  1237. * that the caller is currently not available, then he will call this function
  1238. * so that an appropriate message is sent to the caller.
  1239. *
  1240. * Yes, you just read that correctly. The callee asks the caller what his
  1241. * current status is, and if the caller is currently unavailable, the monitor
  1242. * must send him a message anyway. WTF?
  1243. *
  1244. * This function results in the agent's party_b_free callback being called.
  1245. * It is most likely that you will not need to actually implement the
  1246. * party_b_free callback in an agent because it is not likely that you will
  1247. * need to or even want to send a caller a message indicating the callee's
  1248. * status if the caller himself is not also free.
  1249. *
  1250. * \param core_id The core ID of the CC transaction
  1251. * \retval 0 Successfully alerted the core that party B is free
  1252. * \retval -1 Could not alert the core that party B is free
  1253. */
  1254. int ast_cc_monitor_party_b_free(int core_id);
  1255. /* BEGIN API FOR USE WITH/BY MONITORS */
  1256. /*!
  1257. * \since 1.8
  1258. * \brief Return the number of outstanding CC requests to a specific device
  1259. *
  1260. * \note
  1261. * This function will lock the list of monitors stored on every instance of
  1262. * the CC core. Callers of this function should be aware of this and avoid
  1263. * any potential lock ordering problems.
  1264. *
  1265. * \param name The name of the monitored device
  1266. * \param type The type of the monitored device (e.g. "generic")
  1267. * \return The number of CC requests for the monitor
  1268. */
  1269. int ast_cc_monitor_count(const char * const name, const char * const type);
  1270. /*!
  1271. * \since 1.8
  1272. * \brief Alert the core that a device being monitored has become available.
  1273. *
  1274. * \note
  1275. * The code in the core will take care of making sure that the information gets passed
  1276. * up the ladder correctly.
  1277. *
  1278. * \par core_id The core ID of the corresponding CC transaction
  1279. * \par debug
  1280. * \retval 0 Request successfully queued
  1281. * \retval -1 Request could not be queued
  1282. */
  1283. int __attribute__((format(printf, 2, 3))) ast_cc_monitor_callee_available(const int core_id, const char * const debug, ...);
  1284. /* END API FOR USE WITH/BY MONITORS */
  1285. /* BEGIN API TO BE USED ON CC RECALL */
  1286. /*!
  1287. * \since 1.8
  1288. * \brief Set up a CC recall datastore on a channel
  1289. *
  1290. * \details
  1291. * Implementers of protocol-specific CC agents will need to call this
  1292. * function in order for the channel to have the necessary interfaces
  1293. * to recall.
  1294. *
  1295. * This function must be called by the implementer once it has been detected
  1296. * that an inbound call is a cc_recall. After allocating the channel, call this
  1297. * function, followed by ast_cc_set_cc_interfaces_chanvar. While it would be nice to
  1298. * be able to have the core do this automatically, it just cannot be done given
  1299. * the current architecture.
  1300. */
  1301. int ast_setup_cc_recall_datastore(struct ast_channel *chan, const int core_id);
  1302. /*!
  1303. * \since 1.8
  1304. * \brief Decide if a call to a particular channel is a CC recall
  1305. *
  1306. * \details
  1307. * When a CC recall happens, it is important on the called side to
  1308. * know that the call is a CC recall and not a normal call. This function
  1309. * will determine first if the call in question is a CC recall. Then it
  1310. * will determine based on the chan parameter if the channel is being
  1311. * called is being recalled.
  1312. *
  1313. * As a quick example, let's say a call is placed to SIP/1000 and SIP/1000
  1314. * is currently on the phone. The caller requests CCBS. SIP/1000 finishes
  1315. * his call, and so the caller attempts to recall. Now, the dialplan
  1316. * administrator has set up this second call so that not only is SIP/1000
  1317. * called, but also SIP/2000 is called. If SIP/1000's channel were passed
  1318. * to this function, the return value would be non-zero, but if SIP/2000's
  1319. * channel were passed into this function, then the return would be 0 since
  1320. * SIP/2000 was not one of the original devices dialed.
  1321. *
  1322. * \note
  1323. * This function may be called on a calling channel as well to
  1324. * determine if it is part of a CC recall.
  1325. *
  1326. * \note
  1327. * This function will lock the channel as well as the list of monitors
  1328. * on the channel datastore, though the locks are not held at the same time. Be
  1329. * sure that you have no potential lock order issues here.
  1330. *
  1331. * \param chan The channel to check
  1332. * \param[out] core_id If this is a valid CC recall, the core_id of the failed call
  1333. * will be placed in this output parameter
  1334. * \param monitor_type Clarify which type of monitor type we are looking for if this
  1335. * is happening on a called channel. For incoming channels, this parameter is not used.
  1336. * \retval 0 Either this is not a recall or it is but this channel is not part of the recall
  1337. * \retval non-zero This is a recall and the channel in question is directly involved.
  1338. */
  1339. int ast_cc_is_recall(struct ast_channel *chan, int *core_id, const char * const monitor_type);
  1340. /*!
  1341. * \since 1.8
  1342. * \brief Get the associated monitor given the device name and core_id
  1343. *
  1344. * \details
  1345. * The function ast_cc_is_recall is helpful for determining if a call to
  1346. * a specific channel is a recall. However, once you have determined that
  1347. * this is a recall, you will most likely need access to the private data
  1348. * within the associated monitor. This function is what one uses to get
  1349. * that monitor.
  1350. *
  1351. * \note
  1352. * This function locks the list of monitors that correspond to the core_id
  1353. * passed in. Be sure that you have no potential lock order issues when
  1354. * calling this function.
  1355. *
  1356. * \param core_id The core ID to which this recall corresponds. This likely will
  1357. * have been obtained using the ast_cc_is_recall function
  1358. * \param device_name Which device to find the monitor for.
  1359. *
  1360. * \retval NULL Appropriate monitor does not exist
  1361. * \retval non-NULL The monitor to use for this recall
  1362. */
  1363. struct ast_cc_monitor *ast_cc_get_monitor_by_recall_core_id(const int core_id, const char * const device_name);
  1364. /*!
  1365. * \since 1.8
  1366. * \brief Set the first level CC_INTERFACES channel variable for a channel.
  1367. *
  1368. * \note
  1369. * Implementers of protocol-specific CC agents should call this function after
  1370. * calling ast_setup_cc_recall_datastore.
  1371. *
  1372. * \note
  1373. * This function will lock the channel as well as the list of monitors stored
  1374. * on the channel's CC recall datastore, though neither are held at the same
  1375. * time. Callers of this function should be aware of potential lock ordering
  1376. * problems that may arise.
  1377. *
  1378. * \details
  1379. * The CC_INTERFACES channel variable will have the interfaces that should be
  1380. * called back for a specific PBX instance.
  1381. *
  1382. * \param chan The channel to set the CC_INTERFACES variable on
  1383. */
  1384. int ast_cc_agent_set_interfaces_chanvar(struct ast_channel *chan);
  1385. /*!
  1386. * \since 1.8
  1387. * \brief Set the CC_INTERFACES channel variable for a channel using an
  1388. * \verbatim extension@context \endverbatim as a starting point
  1389. *
  1390. * \details
  1391. * The CC_INTERFACES channel variable will have the interfaces
  1392. * that should be called back for a specific PBX instance. This
  1393. * version of the function is used mainly by local channels,
  1394. * wherein we need to set CC_INTERFACES based on an extension
  1395. * and context that appear in the middle of the tree of dialed
  1396. * interfaces.
  1397. *
  1398. * \note
  1399. * This function will lock the channel as well as the list of monitors stored
  1400. * on the channel's CC recall datastore, though neither are held at the same
  1401. * time. Callers of this function should be aware of potential lock ordering
  1402. * problems that may arise.
  1403. *
  1404. * \param chan The channel to set the CC_INTERFACES variable on
  1405. * \param extension The name of the extension for which we're setting the variable.
  1406. * This should be in the form of \verbatim exten@context \endverbatim
  1407. */
  1408. int ast_set_cc_interfaces_chanvar(struct ast_channel *chan, const char * const extension);
  1409. /*!
  1410. * \since 1.8
  1411. * \brief Make CCBS available in the case that ast_call fails
  1412. *
  1413. * In some situations, notably if a call-limit is reached in SIP, ast_call will fail
  1414. * due to Asterisk's knowing that the desired device is currently busy. In such a situation,
  1415. * CCBS should be made available to the caller.
  1416. *
  1417. * One caveat is that this may only be used if generic monitoring is being used. The reason
  1418. * is that since Asterisk determined that the device was busy without actually placing a call to it,
  1419. * the far end will have no idea what call we are requesting call completion for if we were to send
  1420. * a call completion request.
  1421. */
  1422. void ast_cc_call_failed(struct ast_channel *incoming, struct ast_channel *outgoing, const char * const dialstring);
  1423. /*!
  1424. * \since 1.8
  1425. * \brief Callback made from ast_cc_callback for certain channel types
  1426. *
  1427. * \param inbound Incoming asterisk channel.
  1428. * \param cc_params The CC configuration parameters for the outbound target
  1429. * \param monitor_type The type of monitor to use when CC is requested
  1430. * \param device_name The name of the outbound target device.
  1431. * \param dialstring The dial string used when calling this specific interface
  1432. * \param private_data If a native monitor is being used, and some channel-driver-specific private
  1433. * data has been allocated, then this parameter should contain a pointer to that data. If using a generic
  1434. * monitor, this parameter should remain NULL. Note that if this function should fail at some point,
  1435. * it is the responsibility of the caller to free the private data upon return.
  1436. *
  1437. * \details
  1438. * For channel types that fail ast_request when the device is busy, we call into the
  1439. * channel driver with ast_cc_callback. This is the callback that is called in that
  1440. * case for each device found which could have been returned by ast_request.
  1441. *
  1442. * This function creates a CC control frame payload, simulating the act of reading
  1443. * it from the nonexistent outgoing channel's frame queue. We then handle this
  1444. * simulated frame just as we would a normal CC frame which had actually been queued
  1445. * by the channel driver.
  1446. */
  1447. void ast_cc_busy_interface(struct ast_channel *inbound, struct ast_cc_config_params *cc_params,
  1448. const char *monitor_type, const char * const device_name, const char * const dialstring, void *private_data);
  1449. /*!
  1450. * \since 1.8
  1451. * \brief Create a CC Control frame
  1452. *
  1453. * \details
  1454. * chan_dahdi is weird. It doesn't seem to actually queue frames when it needs to tell
  1455. * an application something. Instead it wakes up, tells the application that it has data
  1456. * ready, and then based on set flags, creates the proper frame type. For chan_dahdi, we
  1457. * provide this function. It provides us the data we need, and we'll make its frame for it.
  1458. *
  1459. * \param chan A channel involved in the call. What we want is on a datastore on both incoming
  1460. * and outgoing so either may be provided
  1461. * \param cc_params The CC configuration parameters for the outbound target
  1462. * \param monitor_type The type of monitor to use when CC is requested
  1463. * \param device_name The name of the outbound target device.
  1464. * \param dialstring The dial string used when calling this specific interface
  1465. * \param service What kind of CC service is being offered. (CCBS/CCNR/etc...)
  1466. * \param private_data If a native monitor is being used, and some channel-driver-specific private
  1467. * data has been allocated, then this parameter should contain a pointer to that data. If using a generic
  1468. * monitor, this parameter should remain NULL. Note that if this function should fail at some point,
  1469. * it is the responsibility of the caller to free the private data upon return.
  1470. * \param[out] frame The frame we will be returning to the caller. It is vital that ast_frame_free be
  1471. * called on this frame since the payload will be allocated on the heap.
  1472. * \retval -1 Failure. At some point there was a failure. Do not attempt to use the frame in this case.
  1473. * \retval 0 Success
  1474. */
  1475. int ast_cc_build_frame(struct ast_channel *chan, struct ast_cc_config_params *cc_params,
  1476. const char *monitor_type, const char * const device_name,
  1477. const char * const dialstring, enum ast_cc_service_type service, void *private_data,
  1478. struct ast_frame *frame);
  1479. /*!
  1480. * \brief Callback made from ast_cc_callback for certain channel types
  1481. * \since 1.8
  1482. *
  1483. * \param chan A channel involved in the call. What we want is on a datastore on both incoming and outgoing so either may be provided
  1484. * \param cc_params The CC configuration parameters for the outbound target
  1485. * \param monitor_type The type of monitor to use when CC is requested
  1486. * \param device_name The name of the outbound target device.
  1487. * \param dialstring The dial string used when calling this specific interface
  1488. * \param private_data If a native monitor is being used, and some channel-driver-specific private
  1489. * data has been allocated, then this parameter should contain a pointer to that data. If using a generic
  1490. * monitor, this parameter should remain NULL. Note that if this function should fail at some point,
  1491. * it is the responsibility of the caller to free the private data upon return.
  1492. *
  1493. * \details
  1494. * For channel types that fail ast_request when the device is busy, we call into the
  1495. * channel driver with ast_cc_callback. This is the callback that is called in that
  1496. * case for each device found which could have been returned by ast_request.
  1497. *
  1498. * \return Nothing
  1499. */
  1500. typedef void (*ast_cc_callback_fn)(struct ast_channel *chan, struct ast_cc_config_params *cc_params,
  1501. const char *monitor_type, const char * const device_name, const char * const dialstring, void *private_data);
  1502. /*!
  1503. * \since 1.8
  1504. * \brief Run a callback for potential matching destinations.
  1505. *
  1506. * \note
  1507. * See the explanation in ast_channel_tech::cc_callback for more
  1508. * details.
  1509. *
  1510. * \param inbound
  1511. * \param tech Channel technology to use
  1512. * \param dest Channel/group/peer or whatever the specific technology uses
  1513. * \param callback Function to call when a target is reached
  1514. * \retval Always 0, I guess.
  1515. */
  1516. int ast_cc_callback(struct ast_channel *inbound, const char * const tech, const char * const dest, ast_cc_callback_fn callback);
  1517. /*!
  1518. * \since 1.8
  1519. * \brief Initialize CCSS
  1520. *
  1521. * Performs startup routines necessary for CC operation.
  1522. *
  1523. * \retval 0 Success
  1524. * \retval nonzero Failure
  1525. */
  1526. int ast_cc_init(void);
  1527. #endif /* _ASTERISK_CCSS_H */