SRTP profiles definition use macros only

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index b8acc75..185997d 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -811,9 +811,9 @@
          protection_profiles_index < ssl->conf->dtls_srtp_profile_list_len;
          protection_profiles_index++ )
     {
-        profile_value = mbedtls_ssl_get_srtp_profile_iana_value
+        profile_value = mbedtls_ssl_check_srtp_profile_value
                 ( ssl->conf->dtls_srtp_profile_list[protection_profiles_index] );
-        if( profile_value != 0xFFFF )
+        if( profile_value != MBEDTLS_TLS_SRTP_UNSET )
         {
             MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_write_use_srtp_ext, add profile: %04x",
                                         profile_value ) );
@@ -1823,10 +1823,9 @@
                                    const unsigned char *buf,
                                    size_t len )
 {
-    mbedtls_ssl_srtp_profile server_protection = MBEDTLS_SRTP_UNSET_PROFILE;
+    mbedtls_ssl_srtp_profile server_protection = MBEDTLS_TLS_SRTP_UNSET;
     size_t i, mki_len = 0;
     uint16_t server_protection_profile_value = 0;
-    const mbedtls_ssl_srtp_profile_info * profile_info;
 
     /* If use_srtp is not configured, just ignore the extension */
     if( ssl->conf->dtls_srtp_profile_list == NULL ||
@@ -1870,14 +1869,16 @@
         return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO );
 
     server_protection_profile_value = ( buf[2] << 8 ) | buf[3];
-    server_protection = mbedtls_ssl_get_srtp_profile_value( server_protection_profile_value );
-    profile_info = mbedtls_ssl_dtls_srtp_profile_info_from_id( server_protection );
-    if( profile_info != NULL )
+    server_protection = mbedtls_ssl_check_srtp_profile_value(
+                    server_protection_profile_value );
+    if( server_protection != MBEDTLS_TLS_SRTP_UNSET )
     {
-        MBEDTLS_SSL_DEBUG_MSG( 3, ( "found srtp profile: %s", profile_info->name ) );
+        MBEDTLS_SSL_DEBUG_MSG( 3, ( "found srtp profile: %s",
+                                      mbedtls_ssl_get_srtp_profile_as_string(
+                                              server_protection ) ) );
     }
 
-    ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_SRTP_UNSET_PROFILE;
+    ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_TLS_SRTP_UNSET;
 
     /*
      * Check we have the server profile in our list
@@ -1886,13 +1887,15 @@
     {
         if( server_protection == ssl->conf->dtls_srtp_profile_list[i] ) {
             ssl->dtls_srtp_info.chosen_dtls_srtp_profile = ssl->conf->dtls_srtp_profile_list[i];
-            MBEDTLS_SSL_DEBUG_MSG( 3, ( "selected srtp profile: %s", profile_info->name ) );
+            MBEDTLS_SSL_DEBUG_MSG( 3, ( "selected srtp profile: %s",
+                                      mbedtls_ssl_get_srtp_profile_as_string(
+                                              server_protection ) ) );
             break;
         }
     }
 
     /* If no match was found : server problem, it shall never answer with incompatible profile */
-    if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_SRTP_UNSET_PROFILE )
+    if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET )
     {
         mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
                                         MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE );
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index f774b40..9dc08d2 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -781,10 +781,9 @@
                                    const unsigned char *buf,
                                    size_t len )
 {
-    mbedtls_ssl_srtp_profile client_protection = MBEDTLS_SRTP_UNSET_PROFILE;
+    mbedtls_ssl_srtp_profile client_protection = MBEDTLS_TLS_SRTP_UNSET;
     size_t i,j;
     size_t profile_length,mki_length;
-    const mbedtls_ssl_srtp_profile_info *profile_info;
     /*! 2 bytes for profile length and 1 byte for mki len */
     const size_t size_of_lengths = 3;
 
@@ -818,7 +817,7 @@
         return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
     }
 
-   ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_SRTP_UNSET_PROFILE;
+   ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_TLS_SRTP_UNSET;
 
     /* first 2 bytes are protection profile length(in bytes) */
     profile_length = ( buf[0] << 8 ) | buf[1];
@@ -839,12 +838,13 @@
     for( j=0; j < profile_length; j += 2 )
     {
         uint16_t protection_profile_value = buf[j] << 8 | buf[j+1];
-        client_protection = mbedtls_ssl_get_srtp_profile_value( protection_profile_value );
+        client_protection = mbedtls_ssl_check_srtp_profile_value( protection_profile_value );
 
-        profile_info = mbedtls_ssl_dtls_srtp_profile_info_from_id( client_protection );
-        if( profile_info != NULL )
+        if( client_protection != MBEDTLS_TLS_SRTP_UNSET )
         {
-            MBEDTLS_SSL_DEBUG_MSG( 3, ( "found srtp profile: %s", profile_info->name ) );
+            MBEDTLS_SSL_DEBUG_MSG( 3, ( "found srtp profile: %s",
+                                    mbedtls_ssl_get_srtp_profile_as_string(
+                                            client_protection ) ) );
         }
         else
         {
@@ -856,11 +856,13 @@
             if( client_protection == ssl->conf->dtls_srtp_profile_list[i] )
             {
                 ssl->dtls_srtp_info.chosen_dtls_srtp_profile = ssl->conf->dtls_srtp_profile_list[i];
-                MBEDTLS_SSL_DEBUG_MSG( 3, ( "selected srtp profile: %s", profile_info->name ) );
+                MBEDTLS_SSL_DEBUG_MSG( 3, ( "selected srtp profile: %s",
+                                            mbedtls_ssl_get_srtp_profile_as_string(
+                                                    client_protection ) ) );
                 break;
             }
         }
-        if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile != MBEDTLS_SRTP_UNSET_PROFILE )
+        if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile != MBEDTLS_TLS_SRTP_UNSET )
             break;
     }
     buf += profile_length; /* buf points to the mki length */
@@ -2639,7 +2641,7 @@
 
     *olen = 0;
 
-    if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_SRTP_UNSET_PROFILE )
+    if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET )
     {
         return;
     }
@@ -2679,9 +2681,9 @@
     /* protection profile length: 2 */
     buf[4] = 0x00;
     buf[5] = 0x02;
-    profile_value = mbedtls_ssl_get_srtp_profile_iana_value(
+    profile_value = mbedtls_ssl_check_srtp_profile_value(
                                 ssl->dtls_srtp_info.chosen_dtls_srtp_profile );
-    if( profile_value != 0xFFFF )
+    if( profile_value != MBEDTLS_TLS_SRTP_UNSET )
     {
         buf[6] = (unsigned char)( ( profile_value >> 8 ) & 0xFF );
         buf[7] = (unsigned char)( profile_value & 0xFF );
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 6b08445..caaba24 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -4690,29 +4690,24 @@
 #endif /* MBEDTLS_SSL_ALPN */
 
 #if defined(MBEDTLS_SSL_DTLS_SRTP)
-static const mbedtls_ssl_srtp_profile_info srtp_profile_definitions[] =
+#if defined(MBEDTLS_DEBUG_C)
+const char *mbedtls_ssl_get_srtp_profile_as_string ( mbedtls_ssl_srtp_profile profile )
 {
-    { MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80, "MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80" },
-    { MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32, "MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32" },
-    { MBEDTLS_SRTP_NULL_HMAC_SHA1_80, "MBEDTLS_SRTP_NULL_HMAC_SHA1_80" },
-    { MBEDTLS_SRTP_NULL_HMAC_SHA1_32, "MBEDTLS_SRTP_NULL_HMAC_SHA1_32" },
-    { MBEDTLS_SRTP_UNSET_PROFILE, "" }
-};
-
-const mbedtls_ssl_srtp_profile_info *mbedtls_ssl_dtls_srtp_profile_info_from_id( mbedtls_ssl_srtp_profile profile )
-{
-    const mbedtls_ssl_srtp_profile_info *cur = srtp_profile_definitions;
-
-    while( cur->profile != MBEDTLS_SRTP_UNSET_PROFILE )
+    switch( profile )
     {
-        if( cur->profile == profile )
-            return( cur );
-
-        cur++;
+        case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
+            return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80";
+        case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
+            return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32";
+        case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
+            return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80";
+        case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
+            return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32";
+        default: break;
     }
-
-    return( NULL );
+    return( "" );
 }
+#endif /* MBEDTLS_DEBUG_C */
 
 void mbedtls_ssl_conf_srtp_mki_value_supported( mbedtls_ssl_config *conf,
                                                 int support_mki_value )
@@ -4758,10 +4753,10 @@
     {
         switch( profiles[i] )
         {
-            case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80:
-            case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32:
-            case MBEDTLS_SRTP_NULL_HMAC_SHA1_80:
-            case MBEDTLS_SRTP_NULL_HMAC_SHA1_32:
+            case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
+            case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
+            case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
+            case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
                 break;
             default:
                 conf->dtls_srtp_profile_list = NULL;