Skip to content

Commit

Permalink
Some minor bugfixes and changes
Browse files Browse the repository at this point in the history
- added licence info
- ATUsbInterfaceDescriptor: fix adding endpoints to list
- added ExampleCreateScsiBlockDevice
- changed timeout to 5000
- Usb4JavaUsbDeviceCommunication: when claiming interface added code to detachKernelDriver and then claiming device again
- fixed transferredCount in all 4 methods
- BulkInTransfer added check if returned buffer is actually empty
- UsbMassStorageLibrary: added low-level debug code
- UsbMassStorageDevice: fixed transfer type
- int sets flag so that we know if we need to close it
  • Loading branch information
andy.rozman committed Apr 12, 2024
1 parent 9550a8f commit dab26ec
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums;

import com.atech.library.usb.libaums.data.LibAumsException;
Expand All @@ -6,9 +23,12 @@
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;



public class UsbMassStorageLibrary {

public static boolean LOAD_PARTITIONS = true; // loading partitions by default
public static boolean debugModeOnLowLevel = false;

@Getter
public static boolean libraryInitialized = false;
Expand All @@ -27,6 +47,13 @@ public static synchronized Context initLibrary() throws LibAumsException {
throw LibAumsException.createWithLibUsbException("Unable to initialize libusb", result);
}

if (debugModeOnLowLevel) {
result = LibUsb.setOption(context, LibUsb.OPTION_LOG_LEVEL, LibUsb.LOG_LEVEL_DEBUG);
if (result != LibUsb.SUCCESS) {
throw LibAumsException.createWithLibUsbException("failed to set log level", result);
}
}

libraryInitialized = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.atech.library.usb.libaums.data;

import org.usb4java.LibUsbException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.atech.library.usb.libaums.data;

public class UsbConstants {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.atech.library.usb.libaums.data;

import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Data
@Builder
Expand Down Expand Up @@ -35,4 +53,16 @@ public void setVendorId(short vendorId) {
this.vendorId = vendorId;
updateReadableDeviceId();
}

public String readableDeviceId() {
updateReadableDeviceId();
return this.readableDeviceId;
}

public String toString() {
updateReadableDeviceId();
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}


}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
Expand Down Expand Up @@ -69,9 +85,9 @@ public void loadData(ConfigDescriptor descriptor) {
public String toLsUsbString(int pad) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(description);
for (ATUsbInterface anInterface : interfaces) {
stringBuilder.append(anInterface.toLsUsbString(0));
}
// for (ATUsbInterface anInterface : interfaces) {
// stringBuilder.append(anInterface.toLsUsbString(0));
// }
return stringBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
Expand Down Expand Up @@ -177,4 +194,10 @@ public String toLsUsbString() {
return stringBuilder.toString();
}

@Override
public String toString() {
return toLsUsbString();
}


}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.usb4java.DescriptorUtils;
import org.usb4java.EndpointDescriptor;
import org.usb4java.LibUsb;

import javax.usb.UsbEndpointDescriptor;
import java.nio.ByteBuffer;

import static com.atech.library.usb.libaums.data.UsbConstants.USB_DIR_IN;
import static com.atech.library.usb.libaums.data.UsbConstants.USB_DIR_OUT;

@Data
@Accessors(fluent = true)
public class ATUsbEndpointDescriptor implements UsbEndpointDescriptor {

byte bLength;

byte bDescriptorType;

byte bEndpointAddress;

byte bmAttributes;

short wMaxPacketSize;

byte bInterval;

byte bRefresh;

byte bSynchAddress;

ByteBuffer extra;

int extraLength;


Expand Down Expand Up @@ -79,14 +89,11 @@ public String toLsUsbString(int pad) {
}


public int getType() {
// TODO getType what is this
//DescriptorUtils.
return 0;
public int getTransferType() {
return bmAttributes & LibUsb.TRANSFER_TYPE_MASK;
}

public int getDirection() {
// TODO getDirecton what is this?
return 0;
return ((bEndpointAddress & LibUsb.ENDPOINT_IN) == 0) ? USB_DIR_OUT : USB_DIR_IN;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb.device;

import lombok.Data;
Expand Down Expand Up @@ -67,9 +84,8 @@ public void loadData(InterfaceDescriptor interfaceDescriptor) {
for (EndpointDescriptor endpointDescriptor : endpoint) {
ATUsbEndpointDescriptor endpDescriptor = new ATUsbEndpointDescriptor();
endpDescriptor.loadData(endpointDescriptor);
this.endpoints.add(endpDescriptor);
}


}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2024 Andy Rozman <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.atech.library.usb.libaums.usb4java;

import com.atech.library.usb.libaums.UsbMassStorageLibrary;
Expand Down
Loading

0 comments on commit dab26ec

Please sign in to comment.