Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gsm modem usb driver #521

Merged
merged 1 commit into from
Jul 31, 2023
Merged

add gsm modem usb driver #521

merged 1 commit into from
Jul 31, 2023

Conversation

elicec
Copy link
Contributor

@elicec elicec commented Jul 22, 2023

Referenc linux kernel code
drivers/usb/serial/usb_wwan.c
drivers/usb/serial/option.c

@kai-morich
Copy link
Collaborator

kai-morich commented Jul 22, 2023

SET_CONTROL_LINE_STATE = 0x22; is also used in CdcAcm driver and interface / endpoint handling looks basically the same as openSingleInterface there. Have you tried using the CdcAdm driver?

The Linux kernel includes various excotic or very old drivers. For which devices will this driver be used? I could not find your VID/PID.

@elicec
Copy link
Contributor Author

elicec commented Jul 24, 2023

private void openSingleInterface() throws IOException {
            // the following code is inspired by the cdc-acm driver in the linux kernel

            mControlIndex = 0;
            mControlInterface = mDevice.getInterface(0);
            mDataInterface = mDevice.getInterface(0);
            if (!mConnection.claimInterface(mControlInterface, true)) {
                throw new IOException("Could not claim shared control/data interface");
            }

            for (int i = 0; i < mControlInterface.getEndpointCount(); ++i) {
                UsbEndpoint ep = mControlInterface.getEndpoint(i);
                if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) {
                    mControlEndpoint = ep;
                } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
                    mReadEndpoint = ep;
                } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
                    mWriteEndpoint = ep;
                }
            }
            if (mControlEndpoint == null) {
                throw new IOException("No control endpoint");
            }
        }

I try your suggestion, but the device has no ControlEndpoint

@kai-morich
Copy link
Collaborator

the mControlEndpoint is only used to determine mControlIndex which anyway is zero here for the default control endpoint. Does the CdcAcm driver work without this check?

        if (mControlEndpoint == null) {
            throw new IOException("No control endpoint");
        }

Please provide mDevice.getInterface(0).toString()

@elicec
Copy link
Contributor Author

elicec commented Jul 24, 2023

mDevice.getInterface(0).toString()
UsbInterface[mId=0,mAlternateSetting=0,mName=Unisoc Generic Serial,mClass=255,mSubclass=0,mProtocol=0,mEndpoints=[
UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=512,mInterval=0]
UsbEndpoint[mAddress=1,mAttributes=2,mMaxPacketSize=512,mInterval=0]]

It also cant work without the check. It throw IOException("controlTransfer failed");

 private int sendAcmControlMessage(int request, int value, byte[] buf) throws IOException {
            int len = mConnection.controlTransfer(
                    USB_RT_ACM, request, value, mControlIndex, buf, buf != null ? buf.length : 0, 5000);
            if(len < 0) {
                throw new IOException("controlTransfer failed");
            }
            return len;
        }

@kai-morich
Copy link
Collaborator

I see. Your driver also does mConnection.controlTransfer but uses 0 instead of USB_RT_ACM.

@kai-morich
Copy link
Collaborator

The Linux driver is ~10 years old. For which devices will it be used?
If added to the library, others will also ask "when should I use it?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants