Skip to content

Commit

Permalink
v0.7.2. First public version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Mar 26, 2018
1 parent 91ab826 commit d82d265
Show file tree
Hide file tree
Showing 28 changed files with 4,652 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

CFLAGS= -I./inc -lpthread -Wall

all: umtprd

umtprd: obj/umtprd.o obj/mtp.o obj/mtp_datasets.o obj/mtp_helpers.o \
obj/mtp_support_def.o obj/mtp_constant_strings.o obj/fs_handles_db.o \
obj/usb_gadget.o obj/logs_out.o obj/usbstring.o obj/mtp_cfg.o
${CC} -o $@ $^ $(LDFLAGS) -lpthread

obj/umtprd.o: src/umtprd.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp.o: src/mtp.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp_datasets.o: src/mtp_datasets.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp_helpers.o: src/mtp_helpers.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp_support_def.o: src/mtp_support_def.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp_constant_strings.o: src/mtp_constant_strings.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/mtp_cfg.o: src/mtp_cfg.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/fs_handles_db.o: src/fs_handles_db.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/usb_gadget.o: src/usb_gadget.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/logs_out.o: src/logs_out.c
${CC} -o $@ $^ -c $(CFLAGS)

obj/usbstring.o: src/usbstring.c
${CC} -o $@ $^ -c $(CFLAGS)

clean:
rm -Rf *.o .*.o .*.o.* *.ko .*.ko *.mod.* .*.mod.* .*.cmd umtprd obj
mkdir obj

37 changes: 37 additions & 0 deletions conf/S98uMTPrd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

GADGETFS_PATH=/dev/gadget
UMTPRD_DAEMON_NAME=uMTPrd
UMTPRD_DAEMON_PATH=/usr/bin/umtprd.sh
UMTPRD_DAEMON_OPTS=
UMTPRD_DAEMON_USER=root

case "$1" in
start)
echo -n "Start uMTPrd deamon :"
if [ ! -f "$GADGETFS_PATH" ]; then
mkdir $GADGETFS_PATH
fi
mount -t gadgetfs gadgetfs $GADGETFS_PATH
start-stop-daemon -S --background --name $UMTPRD_DAEMON_NAME \
--chuid $UMTPRD_DAEMON_USER \
--exec $UMTPRD_DAEMON_PATH \
-- $UMTPRD_DAEMON_OPTS
echo "DONE"
;;
stop)
printf -n "Stop uMTPrd deamon :"
start-stop-daemon --name $UMTPRD_DAEMON_NAME --K -s 9
echo " DONE"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit $?

49 changes: 49 additions & 0 deletions conf/umtprd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# uMTP Responder config file
# Must be copied to /etc/umtprd/umtprd.conf
#

#storage command : Create add a storage entry point. Up to 16 entry points supported
#Syntax : storage "PATH" "NAME"

storage "/" "root folder"
storage "/home" "home folder"

# Set the USB manufacturer string

manufacturer "Viveris Technologies"

# Set the USB Product string

product "The Viveris Product !"

# Set the USB Serial number string

serial "01234567"

# Set the USB interface string. Should be always "MTP"

interface "MTP"

# Set the USB Vendor ID, Product ID and class

usb_vendor_id 0x1D6B # Linux Foundation
usb_product_id 0x0100 # PTP Gadget
usb_class 0x6 # Image
usb_subclass 0x1 # Still Imaging device
usb_protocol 0x1 #

# Device version

usb_dev_version 0x3008

# USB gadget device driver path (set here for the Sama5D2Xplained board)

usb_dev_path "/dev/gadget/atmel_usba_udc"
usb_epin_path "/dev/gadget/ep1"
usb_epout_path "/dev/gadget/ep2"
usb_epint_path "/dev/gadget/ep3"

# Max USB packet size

usb_max_packet_size 0x40
5 changes: 5 additions & 0 deletions conf/umtprd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#/bin/sh

while [ test ]; do
/usr/bin/umtprd
done
50 changes: 50 additions & 0 deletions inc/default_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* uMTP Responder
* Copyright (c) 2018 Viveris Technologies
*
* uMTP Responder is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* uMTP Responder 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 version 3 for more details.
*
* You should have received a copy of the GNU General Public License
* along with uMTP Responder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/**
* @file default_cfg.h
* @brief default settings.
* @author Jean-François DEL NERO <Jean-Francois.DELNERO@viveris.fr>
*/

#ifndef UMTPR_CONF_FILE
#define UMTPR_CONF_FILE "/etc/umtprd/umtprd.conf"
#endif

#define MAX_PACKET_SIZE 512

#define USB_DEV_VENDOR_ID 0x1D6B // Linux Foundation
#define USB_DEV_PRODUCT_ID 0x0100 // PTP Gadget

#define USB_DEV_CLASS 0x6 // Still Imaging device
#define USB_DEV_SUBCLASS 0x1 //
#define USB_DEV_PROTOCOL 0x1 //

#define USB_DEV_VERSION 0x3008

#define USB_DEV "/dev/gadget/atmel_usba_udc"

#define USB_EPIN "/dev/gadget/ep1"
#define USB_EPOUT "/dev/gadget/ep2"
#define USB_EPINTIN "/dev/gadget/ep3"

#define MANUFACTURER "Viveris Technologies"
#define PRODUCT "The Viveris Product !"
#define SERIALNUMBER "01234567"

81 changes: 81 additions & 0 deletions inc/fs_handles_db.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* uMTP Responder
* Copyright (c) 2018 Viveris Technologies
*
* uMTP Responder is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* uMTP Responder 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 version 3 for more details.
*
* You should have received a copy of the GNU General Public License
* along with uMTP Responder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/**
* @file fs_handles_db.h
* @brief Local file system helpers and handles database management.
* @author Jean-François DEL NERO <Jean-Francois.DELNERO@viveris.fr>
*/

typedef struct fs_entry fs_entry;

struct fs_entry
{
uint32_t handle;
uint32_t parent;
uint32_t storage_id;
char * name;
uint32_t flags;
uint32_t size;
uint32_t date;

fs_entry * next;
};

#define ENTRY_IS_DIR 0x00000001
#define ENTRY_IS_DELETED 0x00000002

#define _DEF_FS_HANDLES_ 1

typedef struct fs_handles_db_
{
fs_entry * entry_list;
uint32_t next_handle;

fs_entry * search_entry;
uint32_t handle_search;
uint32_t storage_search;

void * mtp_ctx;
}fs_handles_db;


typedef struct filefoundinfo_
{
int isdirectory;
char filename[256];
int size;
}filefoundinfo;


fs_handles_db * init_fs_db(void * mtp_ctx);
void deinit_fs_db(fs_handles_db * fsh);
int scan_and_add_folder(fs_handles_db * db, char * base, uint32_t parent, uint32_t storage_id);
fs_entry * init_search_handle(fs_handles_db * db, uint32_t parent, uint32_t storage_id);
fs_entry * get_next_child_handle(fs_handles_db * db);
fs_entry * get_entry_by_handle(fs_handles_db * db, uint32_t handle);
fs_entry * get_entry_by_handle_and_storageid(fs_handles_db * db, uint32_t handle, uint32_t storage_id);
fs_entry * add_entry(fs_handles_db * db, filefoundinfo *fileinfo, uint32_t parent, uint32_t storage_id);
fs_entry * alloc_root_entry(fs_handles_db * db, uint32_t storage_id);

FILE * entry_open(fs_handles_db * db, fs_entry * entry);
int entry_read(fs_handles_db * db, FILE * f, unsigned char * buffer_out, int offset, int size);
void entry_close(FILE * f);

char * build_full_path(fs_handles_db * db,char * root_path,fs_entry * entry);
104 changes: 104 additions & 0 deletions inc/logs_out.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* uMTP Responder
* Copyright (c) 2018 Viveris Technologies
*
* uMTP Responder is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* uMTP Responder 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 version 3 for more details.
*
* You should have received a copy of the GNU General Public License
* along with uMTP Responder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/**
* @file logs_out.h
* @brief Log output functions
* @author Jean-François DEL NERO <Jean-Francois.DELNERO@viveris.fr>
*/

#ifndef _INC_DEBUG_OUT_H_
#define _INC_DEBUG_OUT_H_

#ifdef USE_SYSLOG

#include <syslog.h>

#else

#ifdef DEBUG
#include <stdio.h>
#endif

#endif


#ifdef USE_SYSLOG // Syslog usage

#define PRINT_MSG(fmt, args...) syslog(LOG_NOTICE, "[Info] " fmt "\n", \
## args)
#define PRINT_ERROR(fmt, args...) syslog(LOG_ERR, "[Error] " fmt "\n", \
## args)
#define PRINT_WARN(fmt, args...) syslog(LOG_WARNING, "[Warning] " fmt "\n", \
## args)
#ifdef DEBUG

#define PRINT_DEBUG(fmt, args...) syslog(LOG_DEBUG, "[Debug] " fmt "\n", \
## args)
#else

#define PRINT_DEBUG(fmt, args...)

#endif

#else // Stdout usage

#define PRINT_MSG(fmt, args...) { \
fprintf(stdout, \
"[Info] " fmt "\r\n", \
## args); \
fflush(stdout); \
}
#define PRINT_ERROR(fmt, args...) { \
fprintf(stderr, \
"[Error] " fmt "\r\n", \
## args); \
fflush(stderr); \
}
#define PRINT_WARN(fmt, args...) { \
fprintf(stdout, \
"[Warning] " fmt "\r\n",\
## args); \
fflush(stdout); \
}

#ifdef DEBUG
#define PRINT_DEBUG(fmt, args...) { \
fprintf(stdout, \
"[Debug] " fmt "\r\n", \
## args); \
fflush(stdout); \
}
#endif

#ifdef DEBUG

#define PRINT_DEBUG_BUF(x, y) printbuf( x, y );
void printbuf(void * buf,int size);

#else

#define PRINT_DEBUG(x...)
#define PRINT_DEBUG_BUF(x, y)

#endif

#endif

#endif
Loading

0 comments on commit d82d265

Please sign in to comment.