| /****************************************************************************** |
| *(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_PROTOCOL_H |
| #define MBIM_PROTOCOL_H |
| |
| /****************************************************************************** |
| * Include files |
| ******************************************************************************/ |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include "mbim_types.h" |
| |
| /****************************************************************************** |
| * Define |
| ******************************************************************************/ |
| #define MBIM_DEVICE_FILE "/dev/mbim" |
| #define MBIM_MAX_CONTROL_TRANS_DEFAULT (64) |
| |
| |
| /****************************************************************************** |
| * Enums |
| ******************************************************************************/ |
| /////////////////////////////////////////////////////// |
| // Message from Host to Function (MBIMv1.0 Sec 9.3) |
| ////////////////////////////////////////////////////// |
| typedef enum _MBIM_COMMAND_TYPE_OPERATION_ENUM |
| { |
| MBIM_QUERY_COMMAND, |
| MBIM_SET_COMMAND |
| }MBIM_COMMAND_TYPE_OPERATION_ENUM; |
| |
| |
| |
| /////////////////////////////////////////////////////// |
| // Message from Host to Function (MBIMv1.0 Sec 9.3) |
| ////////////////////////////////////////////////////// |
| typedef enum _MBIM_MESSAGE_FROM_HOST_ENUM |
| { |
| MBIM_OPEN_MSG_E = 1, |
| MBIM_CLOSE_MSG_E, |
| MBIM_COMMAND_MSG_E, |
| MBIM_HOST_ERROR_MSG_E, |
| } MBIM_MESSAGE_FROM_HOST_ENUM; |
| |
| /////////////////////////////////////////////////////// |
| // Message from Funtion to Host (MBIMv1.0 Sec 9.4) |
| ////////////////////////////////////////////////////// |
| typedef enum _MBIM_MESSAGE_TO_HOST_ENUM |
| { |
| MBIM_OPEN_DONE_E = 0x80000001, |
| MBIM_CLOSE_DONE_E, |
| MBIM_COMMAND_DONE_E, |
| MBIM_FUNCTION_ERROR_MSG_E, |
| MBIM_INDICATE_STATUS_MSG_E = 0X80000007 |
| } MBIM_MESSAGE_TO_HOST_ENUM; |
| |
| |
| typedef enum _MBIM_PROTOCOL_ERROR_CODES_ENUM |
| { |
| MBIM_ERROR_NO_ERROR = 0, |
| MBIM_ERROR_TIMEOUT_FRAGMENT = 1, |
| MBIM_ERROR_FRAGMENT_OUT_OF_SEQUENCE, |
| MBIM_ERROR_LENGTH_MISMATCH, |
| MBIM_ERROR_DUPLICATED_TID, |
| MBIM_ERROR_NOT_OPENED, |
| MBIM_ERROR_UNKNOWN, |
| MBIM_ERROR_CANCEL, |
| MBIM_ERROR_MAX_TRANSFER, |
| MBIM_ERROR_MAX = 0x7FFFFFFF |
| }MBIM_PROTOCOL_ERROR_CODES_ENUM; |
| |
| ///////////////////////////////////////////////////////// |
| // MBIM Status CODE (MBIMv1.0 Table 9.15) |
| //////////////////////////////////////////////////////// |
| typedef enum _MBIM_STATUS_CODE_ENUM |
| { |
| MBIM_STATUS_SUCCESS = 0, |
| MBIM_STATUS_BUSY, |
| MBIM_STATUS_FAILURE, |
| MBIM_STATUS_SIM_NOT_INSERTED, |
| MBIM_STATUS_BAD_SIM, |
| MBIM_STATUS_PIN_REQUIERED, //5 |
| MBIM_STATUS_PIN_DISABLED, |
| MBIM_STATUS_NOT_REGISTERED, |
| MBIM_STATUS_PROVIDERS_NOT_FOUND, |
| MBIM_STATUS_NO_DEVICE_SUPPORT, |
| MBIM_STATUS_PROVIDER_NOT_VISIBLE, //10 |
| MBIM_STATUS_DATA_CLASS_NOT_AVAILABLE, |
| MBIM_STATUS_PACKET_SERVICE_DETACHED, |
| MBIM_STATUS_MAX_ACTIVATED_CONTEXTS, |
| MBIM_STATUS_NOT_INITIALIZED, |
| MBIM_STATUS_VOICE_CALL_IN_PROGRESS, //15 |
| MBIM_STATUS_CONTEXT_NOT_ACTIVATED, |
| MBIM_STATUS_SERVICE_NOT_ACTIVATED, |
| MBIM_STATUS_INVALID_ACCESS_STRING, |
| MBIM_STATUS_INVALID_USER_NAME_PWD, |
| MBIM_STATUS_RADIO_POWER_OFF, //20 |
| MBIM_STATUS_INVALID_PARAMETERS, |
| MBIM_STATUS_READ_FAILURE, |
| MBIM_STATUS_WRITE_FAILURE, |
| MBIM_Reserved_Reserved, |
| MBIM_STATUS_NO_PHONEBOOK, //25 |
| MBIM_STATUS_PARAMETER_TOO_LONG, |
| MBIM_STATUS_STK_BUSY, |
| MBIM_STATUS_OPERATION_NOT_ALLOWED, |
| MBIM_STATUS_MEMORY_FAILURE, |
| MBIM_STATUS_INVALID_MEMORY_INDEX, //30 |
| MBIM_STATUS_MEMORY_FULL, |
| MBIM_STATUS_FILTER_NOT_SUPPORTED, |
| MBIM_STATUS_DSS_INSTANCE_LIMIT, |
| MBIM_STATUS_INVALID_DEVICE_SERVICE_OPERATION, |
| MBIM_STATUS_AUTH_INCORRECT_AUTN, //35 |
| MBIM_STATUS_AUTH_SYNC_FAILURE, |
| MBIM_STATUS_AUTH_AMF_NOT_SET, |
| MBIM_STATUS_CONTEXT_NOT_SUPPORTED, //38 |
| |
| MBIM_STATUS_SMS_UNKNOWN_SMSC_ADDRESS = 100, |
| MBIM_STATUS_SMS_NETWORK_TIMEOUT, |
| MBIM_STATUS_SMS_LANG_NOT_SUPPORTED, |
| MBIM_STATUS_SMS_ENCODING_NOT_SUPPORTED, |
| MBIM_STATUS_SMS_FORMAT_NOT_SUPPORTED, //104 |
| MBIM_STATUS_MAX = 0x7FFFFFFF |
| }MBIM_STATUS_CODE_ENUM; |
| |
| #define MBIM_STATUS_MS_NO_LOGICAL_CHANNELS 0x87430001 |
| #define MBIM_STATUS_MS_SELECT_FAILED 0x87430002 |
| #define MBIM_STATUS_MS_INVALID_LOGICAL_CHANNEL 0x87430003 |
| |
| |
| #define UUID_BASIC_CONNECT "\xa2\x89\xcc\x33" "\xbc\xbb" "\x8b\x4f" "\xb6\xb0\x13\x3e\xc2\xaa\xe6\xdf" |
| #define UUID_SMS "\x53\x3f\xbe\xeb" "\x14\xfe" "\x44\x67" "\x9f\x90\x33\xa2\x23\xe5\x6c\x3f" |
| #define UUID_USSD "\xe5\x50\xa0\xc8" "\x5e\x82" "\x47\x9e" "\x82\xf7\x10\xab\xf4\xc3\x35\x1f" |
| #define UUID_PHONEBOOK "\x4b\xf3\x84\x76" "\x1e\x6a" "\x41\xdb" "\xb1\xd8\xbe\xd2\x89\xc2\x5b\xdb" |
| #define UUID_STK "\xd8\xf2\x01\x31" "\xfc\xb5" "\x4e\x17" "\x86\x02\xd6\xed\x38\x16\x16\x4c" |
| #define UUID_AUTH "\x1d\x2b\x5f\xf7" "\x0a\xa1" "\x48\xb2" "\xaa\x52\x50\xf1\x57\x67\x17\x4e" |
| #define UUID_DSS "\xc0\x8a\x26\xdd" "\x77\x18" "\x43\x82" "\x84\x82\x6e\x0d\x58\x3c\x4d\x0e" |
| #define UUID_BASIC_CONNECT_EXTENSIONS "\x3d\x01\xdc\xc5" "\xfe\xf5" "\x4d\x05" "\x0d\x3a\xbe\xf7\x05\x8e\x9a\xaf" |
| #define UUID_MS_UICC_LOW_LEVEL "\xC2\xF6\x58\x8E" "\xF0\x37" "\x4B\xC9" "\x86\x65\xF4\xD4\x4B\xD0\x93\x67" |
| |
| typedef enum _UUID_BASIC_CONNECT_ENUM |
| { |
| UUID_BASIC_CONNECT_INDEX = 0, |
| UUID_SMS_INDEX, |
| UUID_USSD_INDEX, |
| UUID_PHONEBOOK_INDEX, |
| UUID_STK_INDEX, |
| UUID_AUTH_INDEX, |
| UUID_DSS_INDEX, |
| UUID_BASIC_CONNECT_EXTENSIONS_INDEX, |
| UUID_MS_UICC_LOW_LEVEL_INDEX, |
| UUID_MAX_SERVICE_INDEX |
| }UUID_BASIC_CONNECT_ENUM; |
| |
| typedef enum _UUID_BASIC_CID_ENUM |
| { |
| UUID_BASIC_CID_DEVICE_CAPS = 1, |
| UUID_SUBSCRIBER_READY_STATUS, |
| UUID_RADIO_STATE, |
| UUID_PIN, |
| UUID_PIN_LIST, |
| UUID_HOME_PROVIDER, |
| UUID_PREFERRED_PROVIDERS, |
| UUID_VISIBLE_PROVIDERS, |
| UUID_REGISTER_STATE, |
| UUID_PACKET_SERVICE, //10 |
| UUID_SIGNAL_STATE, |
| UUID_CONNECT, |
| UUID_PROVISIONED_CONTEXTS, |
| UUID_SERVICE_ACTIVATION, |
| UUID_IP_CONFIGURATION, |
| UUID_DEVICE_SERVICES, |
| UUID_DEVICE_SERVICE_SUBSCRIBE_LIST = 19, |
| UUID_PACKET_STATISTICS, |
| UUID_NETWORK_IDLE_HINT, |
| UUID_EMERGENCY_MODE, |
| UUID_IP_PACKET_FILTERS, |
| UUID_MULTICARRIER_PROVIDERS, |
| UUID_BASIC_MAX |
| }UUID_BASIC_CID_ENUM, *P_UUID_BASIC_CID_ENUM; |
| |
| typedef enum _UUID_SMS_CID_ENUM |
| { |
| UUID_SMS_CONFIGURATION = 1, |
| UUID_SMS_READ, |
| UUID_SMS_SEND, |
| UUID_SMS_DELETE, |
| UUID_SMS_MESSAGE_STORE_STATUS, |
| UUID_SMS_MAX |
| }UUID_SMS_CID_ENUM, *P_UUID_SMS_CID_ENUM; |
| |
| |
| typedef enum _UUID_USSD_CID_ENUM |
| { |
| MBIM_CID_USSD = 1, |
| UUID_USSD_MAX |
| }UUID_USSD_CID_ENUM, *P_UUID_USSD_CID_ENUM; |
| |
| |
| typedef enum _UUID_PHONEBOOK_CID_ENUM |
| { |
| MBIM_CID_PHONEBOOK_CONFIGURATION = 1, |
| MBIM_CID_PHONEBOOK_READ, |
| MBIM_CID_PHONEBOOK_DELETE, |
| MBIM_CID_PHONEBOOK_WRITE, |
| UUID_CID_PHONEBOOK_MAX |
| }UUID_PHONEBOOK_CID_ENUM, *P_UUID_PHONEBOOK_CID_ENUM; |
| |
| |
| |
| typedef enum _UUID_STK_CID_ENUM |
| { |
| MBIM_CID_STK_PAC = 1, |
| MBIM_CID_STK_TERMINAL_RESPONSE, |
| MBIM_CID_STK_ENVELOPE, |
| UUID_CID_STK_MAX |
| }UUID_STK_CID_ENUM, *P_UUID_STK_CID_ENUM; |
| |
| |
| typedef enum _UUID_AUTH_CID_ENUM |
| { |
| MBIM_CID_AKA_AUTH = 1, |
| MBIM_CID_AKAP_AUTH, |
| MBIM_CID_SIM_AUTH, |
| UUID_CID_AUTH_MAX |
| }UUID_AUTH_CID_ENUM, *P_UUID_AUTH_CID_ENUM; |
| |
| |
| typedef enum _UUID_DSS_CID_ENUM |
| { |
| MBIM_CID_DSS_CONNECT = 1, |
| UUID_CID_DSS_MAX |
| }UUID_DSS_CID_ENUM, *P_UUID_DSS_CID_ENUM; |
| |
| |
| typedef enum _UUID_BASICEXT_CID_ENUM |
| { |
| MBIM_MS_PROVISIONED_CONTEXT_V2 = 1, |
| MBIM_CID_MS_NETWORK_BLACKLIST, |
| MBIM_CID_MS_LTE_ATTACH_CONFIG, |
| MBIM_CID_MS_LTE_ATTACH_STATUS, |
| MBIM_CID_MS_SYS_CAPS, |
| MBIM_CID_MS_DEVICE_CAPS_V2, |
| MBIM_CID_MS_DEVICE_SLOT_MAPPINGS, |
| MBIM_CID_MS_SLOT_INFO_STATUS, |
| MBIM_CID_PCO, |
| MBIM_CID_MS_DEVICE_RESET, |
| MBIM_CID_BASE_STATIONS_INFO = 11, |
| MBIM_CID_MS_PIN_EX = 14, |
| MBIM_CID_VERSION = 15, |
| MBIM_CID_MS_MODEM_CONFIG = 16, |
| MBIM_CID_MS_REGISTRATION_PARAMS = 17, |
| MBIM_CID_MS_NETWORK_PARAMS = 18, |
| MBIM_CID_MS_WAKE_REASON = 19, |
| UUID_CID_BASICEXT_MAX |
| }UUID_BASICEXT_CID_ENUM, *P_UUID_BASICEXT_CID_ENUM; |
| |
| typedef enum _UUID_MS_UICC_CID_ENUM |
| { |
| MBIM_CID_MS_UICC_ATR = 1, |
| MBIM_CID_MS_UICC_OPEN_CHANNEL = 2, |
| MBIM_CID_MS_UICC_CLOSE_CHANNEL = 3, |
| MBIM_CID_MS_UICC_APDU = 4, |
| MBIM_CID_MS_UICC_TERMINAL_CAPABILITY = 5, |
| MBIM_CID_MS_UICC_RESET = 6, |
| UUID_CID_MS_UICC_MAX |
| }UUID_MS_UICC_CID_ENUM; |
| |
| /****************************************************************************** |
| * General Structs |
| ******************************************************************************/ |
| |
| /////////////////////////////////////////////////////// |
| // MBIM Message Header (MBIMv1.0 Sec 9.1) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_MESSAGE_HEADER |
| { |
| UINT32 messageType; |
| UINT32 messageLength; |
| UINT32 transactionId; |
| } MBIM_MESSAGE_HEADER, *P_MBIM_MESSAGE_HEADER; |
| |
| /////////////////////////////////////////////////////// |
| // MBIM Fragment Header (MBIMv1.0 Sec 9.2) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_FRAGMENT_HEADER |
| { |
| UINT32 totalFragments; |
| UINT32 currentFragment; |
| } MBIM_FRAGMENT_HEADER, *P_MBIM_FRAGMENT_HEADER; |
| |
| |
| typedef struct _MBIM_DATA_BUFFER |
| { |
| char data[1]; |
| }MBIM_DATA_BUFFER, *P_MBIM_DATA_BUFFER; |
| |
| |
| /****************************************************************************** |
| * Commands |
| ******************************************************************************/ |
| /////////////////////////////////////////////////////// |
| // MBIM open message (MBIMv1.0 Sec 9.3.1) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_OPEN_MSG |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| UINT32 maxControlTransfer; |
| }MBIM_OPEN_MSG, *P_MBIM_OPEN_MSG; |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM close message (MBIMv1.0 Sec 9.3.2) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_CLOSE_MSG |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| }MBIM_CLOSE_MSG, *P_MBIM_CLOSE_MSG; |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM command message (MBIMv1.0 Sec 9.3.3) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_COMMAND_MSG |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_FRAGMENT_HEADER fragmentHeader; |
| MBIM_UUID deviceServiceId; |
| UINT32 cid; |
| UINT32 commandType; |
| UINT32 informationBufferLength; |
| MBIM_DATA_BUFFER InformationBuffer; |
| }MBIM_COMMAND_MSG, *P_MBIM_COMMAND_MSG; |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM Host Error message (MBIMv1.0 Sec 9.3.4) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_HOST_ERROR_MSG |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_PROTOCOL_ERROR_CODES_ENUM errorStatusCode; |
| }MBIM_HOST_ERROR_MSG, *P_MBIM_HOST_ERROR_MSG, |
| MBIM_FUNCTION_ERROR_MSG, *P_MBIM_FUNCTION_ERROR_MSG; |
| |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM open done message (MBIMv1.0 Sec 9.4.1) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_OPEN_DONE |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_STATUS_CODE_ENUM status; |
| }MBIM_OPEN_DONE, *P_MBIM_OPEN_DONE; |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM close done message (MBIMv1.0 Sec 9.4.2) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_CLOSE_DONE |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_STATUS_CODE_ENUM status; |
| }MBIM_CLOSE_DONE, *P_MBIM_CLOSE_DONE; |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM Command done message (MBIMv1.0 Sec 9.4.3) |
| ////////////////////////////////////////////////////// |
| #define FRAGMENT_HDR_SIZE (sizeof(MBIM_MESSAGE_HEADER) + sizeof(MBIM_FRAGMENT_HEADER)) |
| typedef struct _MBIM_COMMAND_DONE |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_FRAGMENT_HEADER fragmentHeader; |
| MBIM_UUID deviceServiceId; |
| UINT32 cid; |
| MBIM_STATUS_CODE_ENUM status; |
| UINT32 informationBufferLength; |
| |
| }MBIM_COMMAND_DONE, *P_MBIM_COMMAND_DONE; |
| |
| |
| |
| /////////////////////////////////////////////////////// |
| // MBIM Command done message (MBIMv1.0 Sec 9.4.4.1) |
| ////////////////////////////////////////////////////// |
| typedef struct _MBIM_INDICATION_STATUS_MSG |
| { |
| MBIM_MESSAGE_HEADER messageHeader; |
| MBIM_FRAGMENT_HEADER fragmentHeader; |
| MBIM_UUID deviceServiceId; |
| UINT32 cid; |
| UINT32 informationBufferLength; |
| |
| }MBIM_INDICATION_STATUS_MSG, *P_MBIM_INDICATION_STATUS_MSG; |
| |
| |
| /****************************************************************************** |
| * Function prototypes |
| ******************************************************************************/ |
| int MbimKernelBind(void); |
| int MbimProcessEncapCommand(char *dataBuf, UINT32 dataLen); |
| int MbimSendOpenDone(UINT32 transId, MBIM_STATUS_CODE_ENUM statusCode); |
| int MbimSendCloseDone(UINT32 transId, MBIM_STATUS_CODE_ENUM statusCode); |
| int MbimSendCommandDone(UINT32 transId, int uuidIndex, int cid, MBIM_STATUS_CODE_ENUM status, int bufLen, char *rspData_p); |
| int MbimSendFunctionErrorMsg(UINT32 transId, MBIM_PROTOCOL_ERROR_CODES_ENUM statusCode); |
| int MbimSendIndicateStatusMsg(int uuidIndex, int cid, int bufLen, char *rspData_p); |
| void MbimHandleCommand (char *dataBuf, int len); |
| void MbimUICCAddChannel(UINT32 channeltag, int channel); |
| void MbimUICCRemoveChannel(UINT32 channeltag, int channel); |
| void MbimInit(void); |
| |
| |
| //#ifdef DUMMY |
| //void dummy_SmsConfigurationNotify(void); |
| //#endif |
| |
| |
| #endif |