| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
|
| 34 |
#include "asterisk/linkedlists.h" |
| 35 |
#include "asterisk/logger.h" |
| 36 |
#include "asterisk/sdp_srtp.h" |
| 37 |
|
| 38 |
|
| 39 |
static struct ast_sdp_crypto_api *sdp_crypto_api; |
| 40 |
|
| 41 |
struct ast_sdp_srtp *ast_sdp_srtp_alloc(void) |
| 42 |
{ |
| 43 |
if (!ast_rtp_engine_srtp_is_registered()) { |
| 44 |
ast_debug(1, "No SRTP module loaded, can't setup SRTP session.\n"); |
| 45 |
return NULL; |
| 46 |
} |
| 47 |
|
| 48 |
return ast_calloc(1, sizeof(struct ast_sdp_srtp)); |
| 49 |
} |
| 50 |
|
| 51 |
void ast_sdp_srtp_destroy(struct ast_sdp_srtp *srtp) |
| 52 |
{ |
| 53 |
struct ast_sdp_srtp *next; |
| 54 |
|
| 55 |
for (next = AST_LIST_NEXT(srtp, sdp_srtp_list); |
| 56 |
srtp; |
| 57 |
srtp = next, next = srtp ? AST_LIST_NEXT(srtp, sdp_srtp_list) : NULL) { |
| 58 |
ast_sdp_crypto_destroy(srtp->crypto); |
| 59 |
srtp->crypto = NULL; |
| 60 |
ast_free(srtp); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void ast_sdp_crypto_destroy(struct ast_sdp_crypto *crypto) |
| 65 |
{ |
| 66 |
if (sdp_crypto_api) { |
| 67 |
sdp_crypto_api->dtor(crypto); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
struct ast_sdp_crypto *ast_sdp_crypto_alloc(void) |
| 72 |
{ |
| 73 |
if (!sdp_crypto_api) { |
| 74 |
return NULL; |
| 75 |
} |
| 76 |
return sdp_crypto_api->alloc(); |
| 77 |
} |
| 78 |
|
| 79 |
int ast_sdp_crypto_process(struct ast_rtp_instance *rtp, struct ast_sdp_srtp *srtp, const char *attr) |
| 80 |
{ |
| 81 |
if (!sdp_crypto_api) { |
| 82 |
return -1; |
| 83 |
} |
| 84 |
return sdp_crypto_api->parse_offer(rtp, srtp, attr); |
| 85 |
} |
| 86 |
|
| 87 |
int ast_sdp_crypto_build_offer(struct ast_sdp_crypto *p, int taglen) |
| 88 |
{ |
| 89 |
if (!sdp_crypto_api) { |
| 90 |
return -1; |
| 91 |
} |
| 92 |
return sdp_crypto_api->build_offer(p, taglen); |
| 93 |
} |
| 94 |
|
| 95 |
const char *ast_sdp_srtp_get_attrib(struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32) |
| 96 |
{ |
| 97 |
if (!sdp_crypto_api) { |
| 98 |
return NULL; |
| 99 |
} |
| 100 |
return sdp_crypto_api->get_attr(srtp, dtls_enabled, default_taglen_32); |
| 101 |
} |
| 102 |
|
| 103 |
char *ast_sdp_get_rtp_profile(unsigned int sdes_active, struct ast_rtp_instance *instance, unsigned int using_avpf, |
| 104 |
unsigned int force_avp) |
| 105 |
{ |
| 106 |
struct ast_rtp_engine_dtls *dtls; |
| 107 |
|
| 108 |
if ((dtls = ast_rtp_instance_get_dtls(instance)) && dtls->active(instance)) { |
| 109 |
if (force_avp) { |
| 110 |
return using_avpf ? "RTP/SAVPF" : "RTP/SAVP"; |
| 111 |
} else { |
| 112 |
return using_avpf ? "UDP/TLS/RTP/SAVPF" : "UDP/TLS/RTP/SAVP"; |
| 113 |
} |
| 114 |
} else { |
| 115 |
if (using_avpf) { |
| 116 |
return sdes_active ? "RTP/SAVPF" : "RTP/AVPF"; |
| 117 |
} else { |
| 118 |
return sdes_active ? "RTP/SAVP" : "RTP/AVP"; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
int ast_sdp_crypto_register(struct ast_sdp_crypto_api *api) |
| 124 |
{ |
| 125 |
if (sdp_crypto_api) { |
| 126 |
return -1; |
| 127 |
} |
| 128 |
sdp_crypto_api = api; |
| 129 |
return 0; |
| 130 |
} |
| 131 |
|
| 132 |
void ast_sdp_crypto_unregister(struct ast_sdp_crypto_api *api) |
| 133 |
{ |
| 134 |
if (sdp_crypto_api == api) { |
| 135 |
sdp_crypto_api = NULL; |
| 136 |
} |
| 137 |
} |