| /****************************************************************************** |
| *(C) Copyright 2014 Marvell International Ltd. |
| * All Rights Reserved |
| ******************************************************************************/ |
| /* ------------------------------------------------------------------------------------------------------------------- |
| * |
| * Filename: mbim_util.h |
| * |
| * Authors: Adrian Zelezniak |
| * |
| * Description: all utiliy functions and macros needed for the MIBM translator |
| * |
| * HISTORY: |
| * Jan 7, 2014 - Initial Version |
| * |
| * Notes: |
| * |
| ******************************************************************************/ |
| #ifndef MBIM_UTIL_H |
| #define MBIM_UTIL_H |
| |
| /****************************************************************************** |
| * Include files |
| ******************************************************************************/ |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <stdarg.h> |
| #if defined (__amd64) |
| #include <stddef.h> |
| #endif |
| |
| #include <sys/socket.h> |
| #include <netinet/in.h> |
| #include <arpa/inet.h> |
| |
| #ifdef HOST_BUILD |
| #include <string.h> |
| #endif |
| |
| #include <unistd.h> |
| #if defined MBIM_MTIL |
| #include "MtilClientAPI.h" |
| #include "MtilAPI.h" |
| #endif |
| |
| #include "mbim_types.h" |
| #include "mbim_protocol.h" |
| #include "mbim_basic.h" |
| |
| /****************************************************************************** |
| * extern defines |
| ******************************************************************************/ |
| #ifndef MIN |
| #define MIN(a,b) ((a)>(b)?(b):(a)) |
| #endif |
| |
| /* Disable compilation/link error - PCAP library currently isn't used */ |
| #define PCAP_CMD_WRITE(b,l) |
| #define PCAP_RSP_WRITE(b,l) |
| |
| |
| #define MBIM_MANAGER_AT_PROPERTY "sys.mbim.manager.at" |
| |
| /****************************************************************************** |
| * Defines |
| ******************************************************************************/ |
| typedef enum _MBIM_ERROR_ENUM |
| { |
| MBIM_OK = 0, |
| MBIM_BIND_ERROR = -1, |
| MBIM_BIND_READ_ERROR = -2, |
| MBIM_BIND_WRITE_ERROR = -3, |
| MBIM_BIND_MEM_ERROR = -4, |
| MBIM_UUID_UKNOWN_ERROR = -5, |
| |
| } MBIM_ERROR_ENUM; |
| |
| |
| #define DEFAULT_ALIGNMENT_BOUNDARY 4 |
| |
| #define ROUND_UP_TO(number, boundary) ((number) += ((number) % (boundary)) ? ((boundary) - ((number) % (boundary))) : 0) |
| #define ROUND_UP(number) ROUND_UP_TO(number, DEFAULT_ALIGNMENT_BOUNDARY) |
| |
| #define ALIGN32(x) (((x) + 3) & 0xFFFFFFFC) |
| #define ALIGNED_OFFSET(OFFSET,SIZE) ALIGN32(OFFSET+SIZE) |
| |
| #define LOG_BUF_SIZE 1024 |
| /****************************************************************************** |
| * MBIM_TLV_IE |
| ******************************************************************************/ |
| |
| //Type values for MBIM_TLV_IE |
| typedef enum _MBIM_TLV_IE_TYPE |
| { |
| MBIM_TLV_TYPE_INVALID = 0, |
| MBIM_TLV_TYPE_UE_POLICIES, |
| MBIM_TLV_TYPE_SINGLE_NSSAI, |
| MBIM_TLV_TYPE_ALLOWED_NSSAI, |
| MBIM_TLV_TYPE_CFG_NSSAI, |
| MBIM_TLV_TYPE_DFLT_CFG_NSSAI, |
| MBIM_TLV_TYPE_PRECFG_DFLT_CFG_NSSAI, |
| MBIM_TLV_TYPE_REJ_NSSAI, |
| MBIM_TLV_TYPE_LADN, |
| MBIM_TLV_TYPE_TAI, |
| MBIM_TLV_TYPE_WCHAR_STR, |
| MBIM_TLV_TYPE_UINT16_TBL, |
| MBIM_TLV_TYPE_EAP_PACKET, |
| MBIM_TLV_TYPE_PCO, |
| MBIM_TLV_TYPE_ROUTE_SELECTION_DESCRIPTORS, |
| MBIM_TLV_TYPE_TRAFFIC_PARAMETERS, |
| MBIM_TLV_TYPE_WAKE_COMMAND, |
| MBIM_TLV_TYPE_WAKE_PACKET = 17, |
| } MBIM_TLV_IE_TYPE; |
| |
| typedef struct _MBIM_TLV_IE |
| { |
| UINT16 Type; |
| UINT8 Reserved; |
| UINT8 PaddingLength; |
| UINT32 DataLength; |
| UINT8 Data[]; |
| } MBIM_TLV_IE, *P_MBIM_TLV_IE; |
| |
| |
| #define MBIM_TLV_HEADER(data) ((P_MBIM_TLV_IE)(data)) |
| |
| #define MBIM_TLV_FIELD_TYPE(data) MBIM_TLV_HEADER (data)->Type |
| #define MBIM_TLV_FIELD_RESERVED(data) MBIM_TLV_HEADER (data)->Reserved |
| #define MBIM_TLV_FIELD_PADDING_LENGTH(data) MBIM_TLV_HEADER (data)->PaddingLength |
| #define MBIM_TLV_FIELD_DATA_LENGTH(data) MBIM_TLV_HEADER (data)->DataLength |
| #define MBIM_TLV_FIELD_DATA(data) MBIM_TLV_HEADER (data)->Data |
| |
| #define MBIM_TLV_GET_TLV_TYPE(data) (MBIM_TLV_IE_TYPE) (MBIM_TLV_FIELD_TYPE (data)) |
| #define MBIM_TLV_GET_DATA_LENGTH(data) (MBIM_TLV_FIELD_DATA_LENGTH (data)) |
| |
| #define MBIM_TLV_LEN(data) (8+MBIM_TLV_GET_DATA_LENGTH(data)+MBIM_TLV_FIELD_PADDING_LENGTH(data)) |
| |
| typedef struct _MBIM_SNSSAI |
| { |
| UINT8 length; |
| UINT8 SliceServiceType; |
| UINT8 sd[3]; |
| UINT8 MappedSst; |
| UINT8 MappedSd[3]; |
| }MBIM_SNSSAI, *P_MBIM_SNSSAI; |
| |
| |
| /****************************************************************************** |
| * External variables |
| ******************************************************************************/ |
| |
| /****************************************************************************** |
| * Function prototypes |
| ******************************************************************************/ |
| void logReceivedMbimMsg(UINT32 msgId, UINT32 transId); |
| void logSentMbimMsg(char *msg); |
| int UUID2Index (P_MBIM_UUID uuid); |
| int Index2UUID (P_MBIM_UUID uuid_p, int uuidIndex); |
| int getNumOfFragments(int mbimMsgSize, int bufLen); |
| |
| #if defined MBIM_MTIL |
| int MtilSimStatus2MbimSubscriberReadyState(int ret_code, int pin_code); |
| int MtilCauseCodeForNwError2Mbim(UINT32 result); |
| int getMaxDataClassSupported(P_MTIL_CNTI_STATUS_MSG pCnti); |
| int getMaxDataClassAvailable(P_MTIL_CNTI_STATUS_MSG pCnti, UINT64 *dlSpeed, UINT64 *ulSpeed); |
| #endif |
| |
| void initSessionDb(int sessionId, char *apn, UINT32 ipType, P_MBIM_UUID contextType, int cid); |
| void resetSessionDb(int sessionId); |
| |
| int getRegisterTech(int dataClass); |
| int RegisterTech2Mbim(int act); |
| int transCregAct2Mbim(int act); |
| |
| |
| int CodeSignalStr2MbimCodedValue(int signalStrength); |
| int CodeFer2MbimCodedValue(float fer); |
| int CodeBer2MbimCodedValue(float ber); |
| |
| int getIpv4MaskLength(UINT32 mask); |
| int getIpv6MaskLength(UINT32 *mask); |
| |
| BOOL checkForNumericOnlyChars(const CHAR * password); |
| |
| void pinListFillPinDescriptor( P_MBIM_PIN_DESC pPinDesc, |
| MBIM_PIN_MODE_ENUM pinMode, |
| MBIM_PIN_FORMAT_ENUM pinFormat, |
| UINT32 pinLengthMax, |
| UINT32 pinLengthMin); |
| |
| void setRoutingTable(int cid); |
| int getSessionIdFromCid(int cid); |
| int getFreeSessionId(void); |
| char hexToNum(char ch); |
| void mbim_disableAutoDial(void); |
| |
| /*Added By JoshuaWang. @0125/2021 */ |
| UINT32 mbim_htonl(UINT32 n); |
| UINT32 mbim_getTotalbitOne(UINT32 value); |
| |
| #define mbim_(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) |
| |
| void __mbim_log_print(int prio, const char *tag, const char *fmt, ...); |
| |
| /////////////////////////////////////////////////// |
| // Translation functions |
| ////////////////////////////////////////////////// |
| int translateSimMsg2MbimSimMsg(int simMsg); |
| int copyStrToUtf16(char *dst, char*src, int sizeOfStr); |
| int copyUtf16ToStr(char *dst, char*src, int sizeOfUtf16); |
| int translateCopsRegMode(int regMode); |
| int translateCgattState(int state); |
| int translateCopsProvider2MbimProvider(int stat); |
| int translateMbimFlag2CmglStat(int flag); |
| int translateCmgrStat2MbimMessageStat(int status); |
| int translateSmsStatus2MbimSmsStatus(int smsStatus); |
| int translateMbimFlag2CmgdFlag(UINT8 mbimFlag); |
| int translateCregRegisterState2Mbim(int registerState); |
| int ReadCOMCfgFileAndSearchValue(char * token, char *value); |
| |
| int at_tok_start(char **p_cur); |
| int at_tok_nextint(char **p_cur, int *p_out); |
| int at_tok_nextstr(char **p_cur, char **p_out); |
| int at_tok_hasmore(char **p_cur); |
| int at_tok_nextbool(char **p_cur, char *p_out); |
| int at_tok_nexthexint(char **p_cur, int *p_out); |
| |
| UINT32 mbimipV4ToUINT(char *addr); |
| UINT32* mbimipV6ToUINT(char *addr); |
| int mbimisv6addrvalid(unsigned int *v6addr); |
| int mbimrsrptorssi(int rsrp); |
| int mbimrsrptocodeval(int rsrp); |
| short int2bcd(int val); |
| char mbim_hexToNum(char ch); |
| int mbim_ConvertHexToNum(char *inData, int inLen, char *outData); |
| void mbim_ConvertNumToHex(char *inData, int inLen, char *outData); |
| |
| UINT32 mbim_tlv_new (UINT8 *tlv, int tlv_type, const UINT8 *tlv_data, UINT32 tlv_data_length); |
| UINT32 mbim_tlv_new_str(UINT8 *tlv, UINT8 *str, int len); |
| UINT32 mbim_tlv_new_u16(UINT8 *tlv, UINT8 *array, int len); |
| int mbim_parse_snssai(P_MBIM_SNSSAI info, char *snssai); |
| UINT32 mbim_tlv_new_precfg_dflt_cfg_nssai(UINT8 *tlv, int tlv_type, int acctype, UINT8 *nssaitlv, int nssaitlv_len); |
| UINT8 * mbim_tlv_new_cfg_nssai(int tlv_type, P_MBIM_SNSSAI pNssai, int num, int *tlv_len); |
| |
| |
| #if defined USER_STRINGS_ARRAY_CLASS |
| /*************************************************** |
| * Strings array functions |
| **************************************************/ |
| #define STRING_ARRAY_DEFAULT_COUNT 5 |
| #define STRING_ARRAY_DEFAULT_GROW 5 |
| |
| typedef struct _StringArrayClassS |
| { |
| char **stringsArray; |
| int stringsCount; |
| int allocCount; |
| }StringArrayClassS; |
| |
| typedef void * StringArrayHandleT; |
| |
| |
| StringArrayHandleT StringArrayInit (int count); |
| int StringArrayAddString(StringArrayHandleT handle, char *string); |
| char ** StringArrayGetStrings(StringArrayHandleT handle); |
| int StringArrayGetCount(StringArrayHandleT handle); |
| void StringArrayFree(StringArrayHandleT handle); |
| #endif //USE_STRINGS_ARRAY_CLASS |
| |
| #endif |