handsfree-audio: Check CVSD when registering agent
authorClaudio Takahasi <claudio.takahasi@openbossa.org>
Thu, 28 Feb 2013 18:52:50 +0000 (15:52 -0300)
committerDenis Kenzior <denkenz@gmail.com>
Fri, 1 Mar 2013 19:32:11 +0000 (13:32 -0600)
This patch makes CVSD codec mandatory when registering a Handsfree
Audio Agent.

src/handsfree-audio.c

index b2d4b97..bfce42a 100644 (file)
@@ -307,6 +307,7 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
        unsigned char *codecs;
        DBusMessageIter iter, array;
        int length, i;
+       gboolean has_cvsd = FALSE;
 
        if (agent)
                return __ofono_error_in_use(msg);
@@ -326,11 +327,17 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
                return __ofono_error_invalid_args(msg);
 
        for (i = 0; i < length; i++) {
-               if (codecs[i] != HFP_CODEC_CVSD &&
-                               codecs[i] != HFP_CODEC_MSBC)
+               if (codecs[i] == HFP_CODEC_CVSD)
+                       has_cvsd = TRUE;
+               else if (codecs[i] != HFP_CODEC_MSBC)
                        return __ofono_error_invalid_args(msg);
        }
 
+       if (has_cvsd == FALSE) {
+               ofono_error("CVSD codec is mandatory");
+               return __ofono_error_invalid_args(msg);
+       }
+
        agent = g_new0(struct agent, 1);
        agent->owner = g_strdup(sender);
        agent->path = g_strdup(path);