forked from norani/libaums-develop
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
15 changed files
with
469 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
} | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
libaums/src/main/java/com/atech/library/usb/libaums/data/LibAumsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
16 changes: 16 additions & 0 deletions
16
libaums/src/main/java/com/atech/library/usb/libaums/data/UsbConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -177,4 +194,10 @@ public String toLsUsbString() { | |
return stringBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toLsUsbString(); | ||
} | ||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
libaums/src/main/java/com/atech/library/usb/libaums/usb/device/ATUsbDeviceDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|
@@ -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; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
libaums/src/main/java/com/atech/library/usb/libaums/usb/device/ATUsbInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -67,9 +84,8 @@ public void loadData(InterfaceDescriptor interfaceDescriptor) { | |
for (EndpointDescriptor endpointDescriptor : endpoint) { | ||
ATUsbEndpointDescriptor endpDescriptor = new ATUsbEndpointDescriptor(); | ||
endpDescriptor.loadData(endpointDescriptor); | ||
this.endpoints.add(endpDescriptor); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
17 changes: 17 additions & 0 deletions
17
libaums/src/main/java/com/atech/library/usb/libaums/usb4java/Usb4JavaManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
Oops, something went wrong.