[PATCH 2/3] libusbg: Add support for functionFS.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recent kernel versions supports creation of functionFS based
functions using configFS, so this library also should support this.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 include/usbg/usbg.h |   14 ++++++++++++++
 src/usbg.c          |   22 +++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index cb1cdcb..5509cdb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -41,6 +41,8 @@
 #define USBG_MAX_STR_LENGTH 256
 #define USBG_MAX_PATH_LENGTH PATH_MAX
 #define USBG_MAX_NAME_LENGTH 40
+/* Dev name for ffs is a part of function name, we subtracs 4 char for "ffs." */
+#define USBG_MAX_DEV_LENGTH (USBG_MAX_NAME_LENGTH - 4)
 
 /**
  * @brief Additional option for usbg_rm_* functions.
@@ -144,6 +146,7 @@ typedef enum
 	F_EEM,
 	F_RNDIS,
 	F_PHONET,
+	F_FFS
 } usbg_function_type;
 
 /**
@@ -174,6 +177,16 @@ typedef struct {
 } usbg_f_phonet_attrs;
 
 /**
+ * @typedef usbg_f_ffs_attrs
+ * @brief Attributes for function fs based functions
+ * @details This is read only and virtual attribute it is non present
+ * on config fs.
+ */
+typedef struct {
+	char dev_name[USBG_MAX_DEV_LENGTH];
+} usbg_f_ffs_attrs;
+
+/**
  * @typedef attrs
  * @brief Attributes for a given function type
  */
@@ -181,6 +194,7 @@ typedef union {
 	usbg_f_serial_attrs serial;
 	usbg_f_net_attrs net;
 	usbg_f_phonet_attrs phonet;
+	usbg_f_ffs_attrs ffs;
 } usbg_function_attrs;
 
 /* Error codes */
diff --git a/src/usbg.c b/src/usbg.c
index 054c603..6f9469a 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -104,6 +104,7 @@ const char *function_names[] =
 	"eem",
 	"rndis",
 	"phonet",
+	"ffs",
 };
 
 #define ERROR(msg, ...) do {\
@@ -800,6 +801,12 @@ static int usbg_parse_function_attrs(usbg_function *f,
 		ret = usbg_read_string(f->path, f->name, "ifname",
 				f_attrs->phonet.ifname);
 		break;
+	case F_FFS:
+		strncpy(f_attrs->ffs.dev_name, f->instance,
+			sizeof(f_attrs->ffs.dev_name) - 1);
+		f_attrs->ffs.dev_name[sizeof(f_attrs->ffs.dev_name) - 1] = '\0';
+		ret = 0;
+		break;
 	default:
 		ERROR("Unsupported function type\n");
 		ret = USBG_ERROR_NOT_SUPPORTED;
@@ -1902,9 +1909,20 @@ int usbg_create_function(usbg_gadget *g, usbg_function_type type,
 	int ret = USBG_ERROR_INVALID_PARAM;
 	int n, free_space;
 
-	if (!g || !f || !instance)
+	if (!g || !f)
 		return ret;
 
+	if (!instance) {
+		/* If someone creates ffs function and doesn't pass instance name
+		   this means that device name from attrs should be used */
+		if (type == F_FFS && f_attrs) {
+			instance = f_attrs->ffs.dev_name;
+			f_attrs = NULL;
+		} else {
+			return ret;
+		}
+	}
+
 	func = usbg_get_function(g, type, instance);
 	if (func) {
 		ERROR("duplicate function name\n");
@@ -2334,6 +2352,8 @@ int  usbg_set_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
 	case F_PHONET:
 		ret = usbg_write_string(f->path, f->name, "ifname", f_attrs->phonet.ifname);
 		break;
+	case F_FFS:
+		ret = USBG_ERROR_NOT_SUPPORTED;
 	default:
 		ERROR("Unsupported function type\n");
 		ret = USBG_ERROR_NOT_SUPPORTED;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux