dundi.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@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 Distributed Universal Number Discovery (DUNDi)
  20. * See also \arg \ref AstDUNDi
  21. */
  22. #ifndef _ASTERISK_DUNDI_H
  23. #define _ASTERISK_DUNDI_H
  24. #include "asterisk/channel.h"
  25. #include "asterisk/utils.h"
  26. #define DUNDI_PORT 4520
  27. typedef struct ast_eid dundi_eid;
  28. struct dundi_hdr {
  29. unsigned short strans; /*!< Source transaction */
  30. unsigned short dtrans; /*!< Destination transaction */
  31. unsigned char iseqno; /*!< Next expected incoming sequence number */
  32. unsigned char oseqno; /*!< Outgoing sequence number */
  33. unsigned char cmdresp; /*!< Command / Response */
  34. unsigned char cmdflags; /*!< Command / Response specific flags*/
  35. unsigned char ies[0];
  36. } __attribute__((__packed__));
  37. struct dundi_ie_hdr {
  38. unsigned char ie;
  39. unsigned char len;
  40. unsigned char iedata[0];
  41. } __attribute__((__packed__));
  42. #define DUNDI_FLAG_RETRANS (1 << 16) /*!< Applies to dtrans */
  43. #define DUNDI_FLAG_RESERVED (1 << 16) /*!< Applies to strans */
  44. enum {
  45. /*! No answer yet */
  46. DUNDI_PROTO_NONE = 0,
  47. /*! IAX, version 2 */
  48. DUNDI_PROTO_IAX = 1,
  49. /*! SIP - Session Initiation Protocol, RFC 3261 */
  50. DUNDI_PROTO_SIP = 2,
  51. /*! ITU H.323 */
  52. DUNDI_PROTO_H323 = 3,
  53. };
  54. enum {
  55. /*! Isn't and can't be a valid number */
  56. DUNDI_FLAG_NONEXISTENT = (0),
  57. /*! Is a valid number */
  58. DUNDI_FLAG_EXISTS = (1 << 0),
  59. /*! Might be valid if you add more digits */
  60. DUNDI_FLAG_MATCHMORE = (1 << 1),
  61. /*! Might be a match */
  62. DUNDI_FLAG_CANMATCH = (1 << 2),
  63. /*! Keep dialtone */
  64. DUNDI_FLAG_IGNOREPAT = (1 << 3),
  65. /*! Destination known to be residential */
  66. DUNDI_FLAG_RESIDENTIAL = (1 << 4),
  67. /*! Destination known to be commercial */
  68. DUNDI_FLAG_COMMERCIAL = (1 << 5),
  69. /*! Destination known to be cellular/mobile */
  70. DUNDI_FLAG_MOBILE = (1 << 6),
  71. /*! No unsolicited calls of any kind through this route */
  72. DUNDI_FLAG_NOUNSOLICITED = (1 << 7),
  73. /*! No commercial unsolicited calls through this route */
  74. DUNDI_FLAG_NOCOMUNSOLICIT = (1 << 8),
  75. };
  76. enum {
  77. DUNDI_HINT_NONE = (0),
  78. /*! TTL Expired */
  79. DUNDI_HINT_TTL_EXPIRED = (1 << 0),
  80. /*! Don't ask for anything beginning with data */
  81. DUNDI_HINT_DONT_ASK = (1 << 1),
  82. /*! Answer not affected by entity list */
  83. DUNDI_HINT_UNAFFECTED = (1 << 2),
  84. };
  85. struct dundi_encblock { /*!< AES-128 encrypted block */
  86. unsigned char iv[16]; /*!< Initialization vector of random data */
  87. unsigned char encdata[0]; /*!< Encrypted / compressed data */
  88. } __attribute__((__packed__));
  89. struct dundi_answer {
  90. dundi_eid eid; /*!< Original source of answer */
  91. unsigned char protocol; /*!< Protocol (DUNDI_PROTO_*) */
  92. unsigned short flags; /*!< Flags relating to answer */
  93. unsigned short weight; /*!< Weight of answers */
  94. unsigned char data[0]; /*!< Protocol specific URI */
  95. } __attribute__((__packed__));
  96. struct dundi_hint {
  97. unsigned short flags; /*!< Flags relating to answer */
  98. unsigned char data[0]; /*!< For data for hint */
  99. } __attribute__((__packed__));
  100. enum {
  101. /*! Success */
  102. DUNDI_CAUSE_SUCCESS = 0,
  103. /*! General unspecified failure */
  104. DUNDI_CAUSE_GENERAL = 1,
  105. /*! Requested entity is dynamic */
  106. DUNDI_CAUSE_DYNAMIC = 2,
  107. /*! No or improper authorization */
  108. DUNDI_CAUSE_NOAUTH = 3,
  109. /*! Duplicate request */
  110. DUNDI_CAUSE_DUPLICATE = 4,
  111. /*! Expired TTL */
  112. DUNDI_CAUSE_TTL_EXPIRED = 5,
  113. /*! Need new session key to decode */
  114. DUNDI_CAUSE_NEEDKEY = 6,
  115. /*! Badly encrypted data */
  116. DUNDI_CAUSE_BADENCRYPT = 7,
  117. };
  118. struct dundi_cause {
  119. unsigned char causecode; /*!< Numerical cause (DUNDI_CAUSE_*) */
  120. char desc[0]; /*!< Textual description */
  121. } __attribute__((__packed__));
  122. struct dundi_peer_status {
  123. unsigned int flags;
  124. unsigned short netlag;
  125. unsigned short querylag;
  126. dundi_eid peereid;
  127. } __attribute__((__packed__));
  128. enum {
  129. DUNDI_PEER_PRIMARY = (1 << 0),
  130. DUNDI_PEER_SECONDARY = (1 << 1),
  131. DUNDI_PEER_UNAVAILABLE = (1 << 2),
  132. DUNDI_PEER_REGISTERED = (1 << 3),
  133. DUNDI_PEER_MOD_OUTBOUND = (1 << 4),
  134. DUNDI_PEER_MOD_INBOUND = (1 << 5),
  135. DUNDI_PEER_PCMOD_OUTBOUND = (1 << 6),
  136. DUNDI_PEER_PCMOD_INBOUND = (1 << 7),
  137. };
  138. #define DUNDI_COMMAND_FINAL (0x80) /*!< Or'd with other flags */
  139. #define DUNDI_COMMAND_ACK (0 | 0x40) /*!< Ack a message */
  140. #define DUNDI_COMMAND_DPDISCOVER 1 /*!< Request discovery */
  141. #define DUNDI_COMMAND_DPRESPONSE (2 | 0x40) /*!< Respond to a discovery request */
  142. #define DUNDI_COMMAND_EIDQUERY 3 /*!< Request information for a peer */
  143. #define DUNDI_COMMAND_EIDRESPONSE (4 | 0x40) /*!< Response to a peer query */
  144. #define DUNDI_COMMAND_PRECACHERQ 5 /*!< Pre-cache Request */
  145. #define DUNDI_COMMAND_PRECACHERP (6 | 0x40) /*!< Pre-cache Response */
  146. #define DUNDI_COMMAND_INVALID (7 | 0x40) /*!< Invalid dialog state (does not require ack) */
  147. #define DUNDI_COMMAND_UNKNOWN (8 | 0x40) /*!< Unknown command */
  148. #define DUNDI_COMMAND_NULL 9 /*!< No-op */
  149. #define DUNDI_COMMAND_REGREQ (10) /*!< Register Request */
  150. #define DUNDI_COMMAND_REGRESPONSE (11 | 0x40) /*!< Register Response */
  151. #define DUNDI_COMMAND_CANCEL (12) /*!< Cancel transaction entirely */
  152. #define DUNDI_COMMAND_ENCRYPT (13) /*!< Send an encrypted message */
  153. #define DUNDI_COMMAND_ENCREJ (14 | 0x40) /*!< Reject an encrypted message */
  154. #define DUNDI_COMMAND_STATUS 15 /*!< Status command */
  155. /*
  156. * Remember that some information elements may occur
  157. * more than one time within a message
  158. */
  159. #define DUNDI_IE_EID 1 /*!< Entity identifier (dundi_eid) */
  160. #define DUNDI_IE_CALLED_CONTEXT 2 /*!< DUNDi Context (string) */
  161. #define DUNDI_IE_CALLED_NUMBER 3 /*!< Number of equivalent (string) */
  162. #define DUNDI_IE_EID_DIRECT 4 /*!< Entity identifier (dundi_eid), direct connect */
  163. #define DUNDI_IE_ANSWER 5 /*!< An answer (struct dundi_answer) */
  164. #define DUNDI_IE_TTL 6 /*!< Max TTL for this request / Remaining TTL for the response (short)*/
  165. #define DUNDI_IE_VERSION 10 /*!< DUNDi version (should be 1) (short) */
  166. #define DUNDI_IE_EXPIRATION 11 /*!< Recommended expiration (short) */
  167. #define DUNDI_IE_UNKNOWN 12 /*!< Unknown command (byte) */
  168. #define DUNDI_IE_CAUSE 14 /*!< Success or cause of failure */
  169. #define DUNDI_IE_REQEID 15 /*!< EID being requested for EIDQUERY*/
  170. #define DUNDI_IE_ENCDATA 16 /*!< AES-128 encrypted data */
  171. #define DUNDI_IE_SHAREDKEY 17 /*!< RSA encrypted AES-128 key */
  172. #define DUNDI_IE_SIGNATURE 18 /*!< RSA Signature of encrypted shared key */
  173. #define DUNDI_IE_KEYCRC32 19 /*!< CRC32 of encrypted key (int) */
  174. #define DUNDI_IE_HINT 20 /*!< Answer hints */
  175. #define DUNDI_IE_DEPARTMENT 21 /*!< Department, for EIDQUERY (string) */
  176. #define DUNDI_IE_ORGANIZATION 22 /*!< Organization, for EIDQUERY (string) */
  177. #define DUNDI_IE_LOCALITY 23 /*!< City/Locality, for EIDQUERY (string) */
  178. #define DUNDI_IE_STATE_PROV 24 /*!< State/Province, for EIDQUERY (string) */
  179. #define DUNDI_IE_COUNTRY 25 /*!< Country, for EIDQUERY (string) */
  180. #define DUNDI_IE_EMAIL 26 /*!< E-mail addy, for EIDQUERY (string) */
  181. #define DUNDI_IE_PHONE 27 /*!< Contact Phone, for EIDQUERY (string) */
  182. #define DUNDI_IE_IPADDR 28 /*!< IP Address, for EIDQUERY (string) */
  183. #define DUNDI_IE_CACHEBYPASS 29 /*!< Bypass cache (empty) */
  184. #define DUNDI_IE_PEERSTATUS 30 /*!< Peer/peer status (struct dundi_peer_status) */
  185. #define DUNDI_FLUFF_TIME 2000 /*!< Amount of time for answer */
  186. #define DUNDI_TTL_TIME 200 /*!< Incremental average time */
  187. #define DUNDI_DEFAULT_RETRANS 5
  188. #define DUNDI_DEFAULT_RETRANS_TIMER 1000
  189. #define DUNDI_DEFAULT_TTL 120 /*!< In seconds/hops like TTL */
  190. #define DUNDI_DEFAULT_VERSION 1
  191. #define DUNDI_DEFAULT_CACHE_TIME 3600 /*!< In seconds */
  192. #define DUNDI_DEFAULT_KEY_EXPIRE 3600 /*!< Life of shared key In seconds */
  193. #define DUNDI_DEF_EMPTY_CACHE_TIME 60 /*!< In seconds, cache of empty answer */
  194. #define DUNDI_WINDOW 1 /*!< Max 1 message in window */
  195. #define DEFAULT_MAXMS 2000
  196. struct dundi_result {
  197. unsigned int flags;
  198. int weight;
  199. int expiration;
  200. int techint;
  201. dundi_eid eid;
  202. char eid_str[20];
  203. char tech[10];
  204. char dest[256];
  205. };
  206. struct dundi_entity_info {
  207. char country[80];
  208. char stateprov[80];
  209. char locality[80];
  210. char org[80];
  211. char orgunit[80];
  212. char email[80];
  213. char phone[80];
  214. char ipaddr[80];
  215. };
  216. /*!
  217. * \brief Lookup the given number in the given dundi context.
  218. * Lookup number in a given dundi context (if unspecified use e164), the given callerid (if specified)
  219. * and return up to maxret results in the array specified.
  220. * \retval the number of results found.
  221. * \retval -1 on a hangup of the channel.
  222. */
  223. int dundi_lookup(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int nocache);
  224. /*! \brief Retrieve information on a specific EID */
  225. int dundi_query_eid(struct dundi_entity_info *dei, const char *dcontext, dundi_eid eid);
  226. /*! \brief Pre-cache to push upstream peers */
  227. int dundi_precache(const char *dcontext, const char *number);
  228. #endif /* _ASTERISK_DUNDI_H */