From patchwork Tue Aug 26 07:02:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Bursztyka X-Patchwork-Id: 382976 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 61F07140107 for ; Tue, 26 Aug 2014 17:04:23 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C0DE99D40B; Tue, 26 Aug 2014 03:04:14 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Qwa75FXMhJEJ; Tue, 26 Aug 2014 03:04:14 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 23E9A17C07A; Tue, 26 Aug 2014 03:03:45 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 023909D3FA for ; Tue, 26 Aug 2014 03:03:44 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bt5aVjkkeUHT for ; Tue, 26 Aug 2014 03:03:37 -0400 (EDT) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id D892D17C039 for ; Tue, 26 Aug 2014 03:03:30 -0400 (EDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 26 Aug 2014 00:03:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,402,1406617200"; d="scan'208";a="563457209" Received: from rd-190.fi.intel.com ([10.237.72.94]) by orsmga001.jf.intel.com with ESMTP; 26 Aug 2014 00:02:46 -0700 From: Tomasz Bursztyka To: hostap@lists.shmoo.com Subject: [PATCH 2/3] wifi_display: Add a utility function to set WFD subelements from ies Date: Tue, 26 Aug 2014 10:02:40 +0300 Message-Id: <1409036561-3739-3-git-send-email-tomasz.bursztyka@linux.intel.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1409036561-3739-1-git-send-email-tomasz.bursztyka@linux.intel.com> References: <1409036561-3739-1-git-send-email-tomasz.bursztyka@linux.intel.com> X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This will be useful to update the WFD subelements from DBus. --- wpa_supplicant/wifi_display.c | 54 +++++++++++++++++++++++++++++++++++++++++++ wpa_supplicant/wifi_display.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/wpa_supplicant/wifi_display.c b/wpa_supplicant/wifi_display.c index dfda8f1..6994a65 100644 --- a/wpa_supplicant/wifi_display.c +++ b/wpa_supplicant/wifi_display.c @@ -263,6 +263,60 @@ int wifi_display_subelem_set(struct wpa_global *global, char *cmd) return 0; } +int wifi_display_subelem_set_from_ies(struct wpa_global *global, + struct wpabuf *ie) +{ + int subelements[MAX_WFD_SUBELEMS] = {}; + const u8 *pos, *end; + int len, subelem; + struct wpabuf *e; + + wpa_printf(MSG_DEBUG, "WFD IEs set: %p - %lu", ie, ie ? ie->used : 0); + + if (ie == NULL || ie->used < 6) + return -1; + + pos = wpabuf_head(ie); + end = pos + wpabuf_len(ie); + + while (end > pos) { + if (pos+3 > end) + break; + + len = WPA_GET_BE16(pos + 1) + 3; + + wpa_printf(MSG_DEBUG, "WFD Sub-Element ID %d - len %d", + *pos, (len - 3)); + + if (pos+len > end) + break; + + subelem = *pos; + if (subelem < MAX_WFD_SUBELEMS && subelements[subelem] == 0) { + e = wpabuf_alloc(len); + if (e == NULL) + return -1; + + wpabuf_put_data(e, pos, len); + + if (global->wfd_subelem[subelem] != NULL) + wpabuf_free(global->wfd_subelem[subelem]); + global->wfd_subelem[subelem] = e; + subelements[subelem] = 1; + } + + pos += len; + } + + for (subelem = 0; subelem < MAX_WFD_SUBELEMS; subelem++) { + if (subelements[subelem] == 0) { + wpabuf_free(global->wfd_subelem[subelem]); + global->wfd_subelem[subelem] = NULL; + } + } + + return wifi_display_update_wfd_ie(global); +} int wifi_display_subelem_get(struct wpa_global *global, char *cmd, char *buf, size_t buflen) diff --git a/wpa_supplicant/wifi_display.h b/wpa_supplicant/wifi_display.h index 67d8bc1..0966bdb 100644 --- a/wpa_supplicant/wifi_display.h +++ b/wpa_supplicant/wifi_display.h @@ -15,6 +15,8 @@ void wifi_display_deinit(struct wpa_global *global); void wifi_display_enable(struct wpa_global *global, int enabled); struct wpabuf *wifi_display_get_wfd_ie(struct wpa_global *global); int wifi_display_subelem_set(struct wpa_global *global, char *cmd); +int wifi_display_subelem_set_from_ies(struct wpa_global *global, + struct wpabuf *ie); int wifi_display_subelem_get(struct wpa_global *global, char *cmd, char *buf, size_t buflen); char * wifi_display_subelem_hex(const struct wpabuf *wfd_subelems, u8 id);