mbim: Add MBIM descriptor utilities

Used to find MBIM Functional and MBIM Extended Functional descriptors
This commit is contained in:
Denis Kenzior 2017-09-19 21:18:26 -05:00
parent 1bfa2749cd
commit 2d4093ae27
3 changed files with 132 additions and 1 deletions

View File

@ -608,7 +608,9 @@ builtin_libadd += @ELL_LIBS@
if MBIMMODEM
mbim_sources = drivers/mbimmodem/mbim.h \
drivers/mbimmodem/mbim.c
drivers/mbimmodem/mbim.c \
drivers/mbimmodem/mbim-desc.h \
drivers/mbimmodem/mbim-desc.c
builtin_modules += mbimmodem
builtin_sources += $(mbim_sources) \

View File

@ -0,0 +1,80 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2017 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "mbim-desc.h"
/*
* Attempts to find MBIM specific descriptors.
*
* Returns true if the MBIM Function descriptor was found, false otherwise.
*/
bool mbim_find_descriptors(const uint8_t *data, size_t data_len,
const struct mbim_desc **out_desc,
const struct mbim_extended_desc **out_ext_desc)
{
bool r = false;
while (data_len > 3) {
uint8_t len = data[0];
if (data[1] != 0x24)
goto next;
/* MBIM v1.0, Table 4-3 */
switch (data[2]) {
case 0x1b:
if (!out_desc)
break;
if (len != sizeof(struct mbim_desc) || data_len < len)
break;
*out_desc = (const struct mbim_desc *) data;
r = true;
break;
case 0x1c:
if (!out_ext_desc)
break;
if (len != sizeof(struct mbim_extended_desc) ||
data_len < len)
break;
*out_ext_desc =
(const struct mbim_extended_desc *) data;
break;
}
next:
data_len -= len;
data += len;
}
return r;
}

View File

@ -0,0 +1,49 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2017 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <linux/types.h>
/* MBIM v1.0, Section 6.4: MBIM Functional Descriptor */
struct mbim_desc {
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
__le16 bcdMBIMVersion;
__le16 wMaxControlMessage;
uint8_t bNumberFilters;
uint8_t bMaxFilterSize;
__le16 wMaxSegmentSize;
uint8_t bmNetworkCapabilities;
} __attribute__ ((packed));
/* MBIM v1.0, Section 6.5: MBIM Extended Functional Descriptor */
struct mbim_extended_desc {
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
__le16 bcdMBIMExtendedVersion;
uint8_t bMaxOutstandingCommandMessages;
__le16 wMTU;
} __attribute__ ((packed));
bool mbim_find_descriptors(const uint8_t *data, size_t data_len,
const struct mbim_desc **out_desc,
const struct mbim_extended_desc **out_ext_desc);