mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-16 16:14:48 -04:00
RCM (Fusée Gelée) support, numerous UI updates and a lot of things for version 2.
This commit is contained in:
parent
3d3fb56f9e
commit
010c33c593
36 changed files with 1572 additions and 92 deletions
33
JNI sources/linux/Makefile
Normal file
33
JNI sources/linux/Makefile
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Compiler
|
||||
CC=gcc
|
||||
# Flags
|
||||
CFLAGS=-O2
|
||||
MKDIR_P = mkdir -p
|
||||
APP_NAME = smashlib.so
|
||||
|
||||
all: x86 amd64
|
||||
|
||||
x86:
|
||||
$(MKDIR_P) ./x86
|
||||
$(CC) ${CFLAGS} -m32 -c -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" smashlib.c -o smashlib_x86.o
|
||||
$(CC) ${CFLAGS} -m32 -shared -fPIC -o ./x86/${APP_NAME} smashlib_x86.o -lc
|
||||
|
||||
amd64:
|
||||
$(MKDIR_P) ./amd64
|
||||
$(CC) ${CFLAGS} -m64 -c -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" smashlib.c -o smashlib_amd64.o
|
||||
$(CC) ${CFLAGS} -m64 -shared -fPIC -o ./amd64/${APP_NAME} smashlib_amd64.o -lc
|
||||
|
||||
clean:
|
||||
rm -rf \
|
||||
smashlib_amd64.o \
|
||||
smashlib_x86.o \
|
||||
./x86 \
|
||||
./amd64
|
||||
|
||||
install: x86 amd64
|
||||
install ./x86/${APP_NAME} ../../src/main/resources/native/linux/x86/
|
||||
install ./amd64/${APP_NAME} ../../src/main/resources/native/linux/amd64/
|
||||
|
||||
uninstall:
|
||||
rm ../../src/main/resources/native/linux/x86/${APP_NAME}
|
||||
rm ../../src/main/resources/native/linux/amd64/${APP_NAME}
|
29
JNI sources/linux/nsusbloader_Utilities_RcmSmash.h
Normal file
29
JNI sources/linux/nsusbloader_Utilities_RcmSmash.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class nsusbloader_Utilities_RcmSmash */
|
||||
|
||||
#ifndef _Included_nsusbloader_Utilities_RcmSmash
|
||||
#define _Included_nsusbloader_Utilities_RcmSmash
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: nsusbloader_Utilities_RcmSmash
|
||||
* Method: smashLinux
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashLinux
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: nsusbloader_Utilities_RcmSmash
|
||||
* Method: smashWindows
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashWindows
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
88
JNI sources/linux/smashlib.c
Executable file
88
JNI sources/linux/smashlib.c
Executable file
|
@ -0,0 +1,88 @@
|
|||
/* NS-USBloader - native libraries for 'special purposes'
|
||||
* Copyright (C) 2020 Dmitry Isaenko
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/usbdevice_fs.h>
|
||||
#include <linux/usb/ch9.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nsusbloader_Utilities_RcmSmash.h"
|
||||
|
||||
struct usbdevfs_urb urb;
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashLinux
|
||||
(JNIEnv * jni_env, jclass this_class, jint bus_id, jint device_addr){
|
||||
int ret_value;
|
||||
|
||||
char *usb_path = (char*)malloc(24 * sizeof(char));
|
||||
|
||||
sprintf(usb_path, "/dev/bus/usb/%03d/%03d", bus_id, device_addr);
|
||||
int fd = open(usb_path, O_RDWR);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
struct usb_ctrlrequest* ctrl_req;
|
||||
|
||||
__u8* buf[0x7000+sizeof(ctrl_req)];
|
||||
|
||||
ctrl_req = (struct usb_ctrlrequest *) buf;
|
||||
ctrl_req->bRequestType = 0x82;
|
||||
ctrl_req->bRequest = USB_REQ_GET_STATUS;
|
||||
ctrl_req->wValue = 0;
|
||||
ctrl_req->wIndex = 0;
|
||||
ctrl_req->wLength = 0x7000;
|
||||
|
||||
memset(&urb, 0, sizeof(urb));
|
||||
urb.type = USBDEVFS_URB_TYPE_CONTROL;
|
||||
urb.endpoint = USB_DIR_IN | 0;
|
||||
urb.buffer = buf;
|
||||
urb.buffer_length = sizeof(buf);
|
||||
//Submit request
|
||||
ret_value = ioctl(fd, USBDEVFS_SUBMITURB, &urb);
|
||||
// If we failed on this step, it's a VERY bad sign. Nothing to do, let's report failure.
|
||||
if (ret_value != 0)
|
||||
return ret_value;
|
||||
// Wait 1/4 sec
|
||||
usleep(250000);
|
||||
struct usbdevfs_urb urb1;
|
||||
// Let's pick reply (everybody does it, right? In non-blocking manner.)
|
||||
ret_value = ioctl(fd, USBDEVFS_REAPURBNDELAY, &urb1);
|
||||
if (ret_value < 0){
|
||||
if (errno == EAGAIN){ // In case of resource temporarily unavailable
|
||||
// Wired.. so much time left. Let's cancel it!
|
||||
ret_value = ioctl(fd, USBDEVFS_DISCARDURB, &urb);
|
||||
// And wait a bit more..
|
||||
usleep(40000);
|
||||
// And try to pick reply. Yes, it's still possible. See /usr/src/linux/drivers/usb/core/devio.c
|
||||
ret_value = ioctl(fd, USBDEVFS_REAPURBNDELAY, &urb1);
|
||||
}
|
||||
}
|
||||
// Leftovers.
|
||||
free(usb_path);
|
||||
// Let's try to close device, but even if we fail with this, nvm.
|
||||
close(fd); // So we won't even write returned value somewhere.
|
||||
return 0;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashWindows
|
||||
(JNIEnv * jni_env, jclass this_class){
|
||||
return -1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue