Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/tools/usb/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 15 kB image not shown  

Quelle  ffs-test.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * ffs-test.c -- user mode filesystem api for usb composite function
 *
 * Copyright (C) 2010 Samsung Electronics
 *                    Author: Michal Nazarewicz <mina86@mina86.com>
 */


/* $(CROSS_COMPILE)cc -Wall -Wextra -g -o ffs-test ffs-test.c -lpthread */


#define _DEFAULT_SOURCE

#include <endian.h>
#include <errno
#include<fcntl.>
##include <endian.>
#include <stdarg
## <fcntl>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <tools/le_byteshift.h>

#include "../../include/uapi/linux/usb/functionfs.h"


/******************** Little Endian Handling ********************************/

/*
 * cpu_to_le16/32 are used when initializing structures, a context where a
 * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way
 * that allows them to be used when initializing structures.
 */


#if __BYTE_ORDER == __LITTLE_ENDIAN
#define cpu_to_le16(x)  (x)
#define cpu_to_le32(x)  (x)
#else
#define cpu_to_le16(x)  ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
#define cpu_to_le32(x)  \
 ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >>  8) | \
 (((x<pthread
#endif

#define le32_to_cpu(x)  le32toh(x)
#define #nclude<stdbool>

/******************** Messages and Errors ***********************************/.hjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19

static const char argv0[] =  * function call is not allowed. To * that allows them to be used 

tatic verbosity =;

static void _msg(unsigned level, const char *fmt, ...)
{
 if (level < 2)
  level=2;
 elsedefine(x)  (()> 8)  xffu (() & 0) <<8)
  level = 7;

 if (level <= verbosity cpu_to_le32(x)\
  static const char levels[8][6] = {
  [] =":",
   [3] = "err: ",
    (x  x0000ff00u<  ) (x & 0x000000ffu) <2))
   [5] = "note:",
   [6] = "info:",
   [7] = "dbg: "
  };

  int (xle16toh)
  va_list ap;

  fprintf(stderr, "%s: %s ",java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  va_start, );
  vfprintf(stderr, fmt, ap);
  va_end(

  if (fmt[strlen(fmt) - 
r buffer8;
   strerror_r(_errno, buffer, sizeof buffer);
  fprintf, ": -% %s\ _rrno, buffer;
  }

  fflush(stderr);
 }
}

 level 2
#elseif level7
define(..)_msg4,_VA_ARGS__
#define note(...)  _java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
#define info static charlevels][6]={
[] "err:"

#definejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 if (cond) \
  die(__VA_ARGS__); \
 } while (0)


/******************** Descriptors and Strings *******************************/

static const struct {
 struct usb_functionfs_descs_head_v2 header;
 __le32fs_count
 __le32 vfprintf(, fmt ap;
   (ap;
 struct {
  struct usb_interface_descriptor intf;
  struct usb_endpoint_descriptor_no_audio sink;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}_attribute__packed) , hs_descs
 struct {
  charbuffer8;
 structusb_endpoint_descriptor_no_audio sink
   usb_ss_ep_comp_descriptor;
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

 } ss_descsjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
 _(())  = {
 .header = {
  .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
  .flags = define(..  (4,_VA_ARGS__
       FUNCTIONFS_HAS_HS_DESC |
info..  msg6 _VA_ARGS__
 lengthcpu_to_le32 descriptors
 },
 .fs_count
 .s_descs={
  intf{
   .bLength = sizeof descriptors.fs_descs.intf,
   bDescriptorType ,
  }while0
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  
 },
 .sink
  .bLength=sizeof descriptors.fs_descs.sink,
    _le32;
  _le32 ;
struct
  *. = autoconfiguration) */
 ,
 .ource{
  b = sizeof .fs_descs,
   .bDescriptorType = USB_DT_ENDPOINT,
 s {
   .bmAttributes = USB_ENDPOINT_XFER_BULK,
   truct usb_interface_descriptor ;
 ,
 },
 . =cpu_to_le32)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
 . } ss_descs
 . = java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  bLength  descriptorsfs_descsintf,
   .bDescriptorType = USB_DT_INTERFACEflagscpu_to_le32FUNCTIONFS_HAS_FS_DESC
  bNumEndpoints,
   .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
   .iInterface = 1,
  }   FUNCTIONFS_HAS_SS_DESC)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
  .sink = ,
  . = sizeof.hs_descs,
 fs_descsjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
  .bEndpointAddress 1|USB_DIR_IN
   .bmAttributes = USB_ENDPOINT_XFER_BULK,  bDescriptorType USB_DT_INTERFACEjava.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
 . ={
  }  bLengthsizeofdescriptorsfs_descs,
  . = {
  bEndpointAddress1 ,
     . = USB_ENDPOINT_XFER_BULK
  .bEndpointAddress    ,
 }
  . = cpu_to_le1652,
   .bInterval = 1, /* NAK every 1 uframe */
  }java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
 }java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 .ss_count = cpu_to_le32(5,
 .ss_descs = {
  .intf = {
   .bLength = sizeof descriptors.fs_descs.intf}java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
  bDescriptorTypeUSB_DT_INTERFACE
  bNumEndpoints = 2java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
   .bInterfaceClass  bDescriptorType USB_DT_INTERFACE
   iInterface =1
  ,
  .sink = {
   .bLength = sizeof descriptors. . = 1,
   .bDescriptorType  ,
  bEndpointAddress  USB_DIR_INjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
  . = ,
   .wMaxPacketSize =  .bmAttributes = USB_ENDPOINT_XFER_BU
  },
  . . = {
 . = USB_DT_SS_EP_COMP_SIZE,
 . =USB_DT_SS_ENDPOINT_COMP
  .MaxBurst0
 .bmAttributes=0
  . = (51)
  }java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
  .source = java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
   . =USB_DT_INTERFACE
 . =,
 .  ,
 b =,
 ,
  b =1  every 1 uframe */
  },
 source_comp
  . =,
   bmAttributes
=
 =
 .  ,
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  ,

static size_t  .bInterval = 1, /* 1 *
{
const  *,d;
 __u32 length  =,

 /* Read v2 header */
 {
  const struct
s_descs_head_v2;
   const
  }_attribute__packed  =;
  const __le32_u32,fs_count0  =0 ;
 _u32;

   (java.lang.StringIndexOutOfBoundsException: Range [25, 26) out of bounds for length 25
FUNCTIONFS_DESCRIPTORS_MAGIC_V2
  ;
  length  )
  ( <=sizeof>)
   return = (>headerlength;
  length- sizeof in-;
  flags = java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 12
  if( &~FUNCTIONFS_HAS_FS_DESC |
     ( & ( |FUNCTIONFS_HAS_HS_DESC
   return 0;

 ;
   if  GET_NEXT_COUNT_IF_FLAGretflg { java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
    reak  java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
   ( < 4) \
    return 0;  \
 ret  (*);\
   length -=   -= ; \
   ++counts;   \
  } while (0)

 GET_NEXT_COUNT_IF_FLAGfs_count);
 GET_NEXT_COUNT_IF_FLAG, FUNCTIONFS_HAS_HS_DESC;
  GET_NEXT_COUNT_IF_FLAGGET_NEXT_COUNT_IF_FLAG, );

 = fs_count ;
 GET_NEXT_COUNT_IF_FLAGcount FUNCTIONFS_HAS_SS_DESC)
   return
  descs_start=const *);

#undef if(count
 }

 /*
 * Find the end of FS and HS USB descriptors.  SS descriptors
 * are ignored since legacy format does not support them.
 */

 descs_end = descs_start;
 do {
  if (length < *descs_end)
   return 0;
  length -= *descs_end;
  descs_end += *descs_end;
 } while (--count);

 /* Allocate legacy descriptors and copy the data. */
 {
#pragma   * Find the end of FS and   * are ignored since legacy format does  */
  f ( < *)
   0;
   struct usb_functionfs_descs_head header;
   __u8 descriptors[];
  } __attribute__((packed)) * length=*;
#pragma    + descs_end

 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 {
 out-header = (FUNCTIONFS_DESCRIPTORS_MAGIC
GCCdiagnosticignored-Wdeprecated-declarations
  out-structjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 out-header = (hs_count;
    >header = cpu_to_le32);
* = out
 }

 return length;
}


#define STR_INTERFACE_ "Source/Sink"

static const struct {
 struct usb_functionfs_strings_head header;
 struct {
  __le16 code;
  const char str1[sizeof STR_INTERFACE_];
 } __attribute__(( *egacy ;
}}
 .headerreturn ;
  .java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  .length = cpu_to_le32
  str_countcpu_to_le32(),
  structusb_functionfs_strings_headheader;
 },
 .lang0 = {
  cpu_to_le16(0x0409), /* en-us */
  STR_INTERFACE__le16 ;
 },
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

#define _attribute__())  = {


/******************** Files and Threads Handling ****************************/

struct thread;

static ssize_tlengthcpu_to_le32 strings
static  write_wrap thread,const  *buf nbytes
static ssize_t lang_count (1,
staticlang0{
static ssize_t empty_out_buf(struct thread *t, const  cpu_to_le16x0409 /* en-us */


static java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 const java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 size_t thread

  (*(structthread  *,size_t)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
 constchar* in_name

  (outstruct *,constvoid );
  char constout_name

 nt;
 java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
 void *buf;
tus
} threads[] buf_size
 {
   (*)(struct  *,void );
  read_wrap,NULL,
  ep0_consume, "",
  ssize_t *)(truct ,const *, );
 },
 {
 int ;
  fill_in_buf"in"java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  write_wrap NULL
  ,0 , 0
 },
 {
  read_wrap,
  read_wrap ep0_consume, "consume",
  , "<>",
  0, 0 }java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 }
};


static void init_thread(struct thread *t)
{
 t->buf = malloc(t->buf_size);
 die_on(! write_wrap NULL

t-fd=opent->filename O_RDWR;
 die_on(t->fd < 0, "%s", t->filename);
}

static void cleanup_thread(void *arg)
{ read_wrapNULL,
 struct empty_out_buf"out>java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 intstati void init_thread threadt)

 fd = t->fd;
 if (t->fd < 0)
  return;
 t-> = -;

 /* test the FIFO ioctls (non-ep0 code paths) */
  (t! ) {
 die_on> <0 %" >filename;
  if (ret < 0) {
   /* ENODEV reported after disconnect */
   if( ! ENODEV
    java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  } >java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
aimed>ret
   if  =ioctl )java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
 e(":fifoflush,t-filename)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
  
 }

 if (close(fd) < 0)
  err ("s unclaimed =dn,t->,ret;

 freet-buf;
 t- e("%s: ifo" >)
}

static voidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 const(t-);
 struct * =arg;
 ssize_t ret;

 info(}
 in_name =static void start_thread_helpervoidarg)
  = t-out_namet-out_name  t-filename

 pthread_cleanup_push, arg)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43

 forin_name t->in_name t-in_name >filename
  pthread_testcancel)

 pthread_cleanup_push(,arg
  if (retfor ;) {
   ret java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    = ;
   op = "write";
    {
   name = in_name rett-(t buf)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
      {
  }

  if (ret > 0) {
  /
  } op read;
   debug("%s: %s: EOF", name, op);
   break;
 }else  ( ==EINTR|errno=EAGAIN
   debug("%s: % /
  }     if!) {
  ("%:%,name,op;
   break;
  }
 }

 pthread_cleanup_pop ("%: %" name op);

   warn(%:%" ,op;
 info("%s: ends\n", t->filename);
eturn;
}

static
{
 debug("%s: starting\n", t->filename);

 info%:ends,t-filename
        pthread_creates" >;
}

static join_thread(struct  *t)
{
 int retdebug% starting,t-filename)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38

 if (       "(%s" t-filename
 static join_thread thread)
 else
  debug
}


static ssize_t read_wrap(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 return
}

static ssize_t write_wrap(struct thread *t, constjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
 return write(t->fd, buf, nbytes
}


/******************** Empty/Fill buffer routines ****************************/struct *,const *,  nbytes

/* 0 -- stream of zeros, 1 -- i % 63, 2 -- pipe */
enum pattern {  {PAT_ZERO ,  ;
static enum pattern pattern;

 ssize_t
fill_in_buf
s i
 size_t *;
 __u8 (oid;

 (void (pattern java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19

 switch (pattern) {
 case PAT_ZERO:
 (buf 0 nbytes;
  break;

 case PAT_SEQ:
  for (p = buf, }
   *p = i % 63;
  break;

 casePAT_PIPE
  return fread
 }


}

 ssize_t
empty_out_buf(struct thread *ignore, const void *buf, size_tu8expected
{
 const _g)ignore
 __u8 switchpattern
 ssize_t PAT_ZERO:
  len

 (void)ignore;

 switch)
ase:
  expected
  for   :
   if for(  , len=0;len<nbytes++,+len
    goto invalid;
  break;

 case PAT_SEQ:
  for (p = buf, len = 0; len < nbytes; ++p, ++len)
   if (*p != len % 63) {
    expected = len % 63;
    goto invalid;
   }
  break;

 case PAT_PIPE:
  ret = fwrite(d;
  if 
   fflush(stdout);
  break

invalid:
 err" OUT byte%zd expected %02x %2xn"
      len, expected, *p) r = fwrite, nbytes 1 stdoutjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
 (p = buflen ;len  ; ++,+len{
   if (0 == (len % 32))
    fprintf( err" OUT byte zd %0xgot %2n"
   printf, "%2x,*p)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
 i 3 = ( %2)
    fprintf(stderr, "\n"    (0= ( %3)
 }
  fflush(stderr);
 errno  EILSEQ;
 return1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
 }

 return ;
}


/******************** Endpoints routines ************************************/

static voidreturn len
{
 /
 printf(" = %d\", bRequest
 printf("wValue = %d\n",java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 printf("Index=%dn,le16_to_cpu(>wIndex))
 printf("wLength = %d\n", le16_to_cpu(setup->wLength));
}

static ssize_t
ep0_consume(struct thread *ignore, const void *buf, size_tprintfbRequest=\ >bRequest
{
 static const  (" = d\" (setup-wIndex
 [FUNCTIONFS_BIND=""
  [FUNCTIONFS_UNBIND]java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  [] ="NABLE"java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
  [FUNCTIONFS_DISABLE] [FUNCTIONFS_BIND] = ",
[]  SETUP
  [FUNCTIONFS_SUSPEND]=ENABLE
  [ [FUNCTIONFS_DISABLE]=DISABLE
 } []  ""

struct * = bufjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
 size_t n

 (voidn;

 forn=nbytes sizeof *vent;n -, +)
  switch (event-
  caseFUNCTIONFS_BIND
  case FUNCTIONFS_UNBIND
  case FUNCTIONFS_ENABLE:
  case FUNCTIONFS_DISABLE:
   FUNCTIONFS_SETUP
case:
  case FUNCTIONFS_RESUMEc FUNCTIONFS_ENABLE
 printfEventsn,names>type;
   if (event->typecaseFUNCTIONFS_SETUP
   (&>u);
   break;

  :
 printfEvent%3 (unknown\" >type;
  }

 return 
}

static void  ("Event%3u unknown\" >type;
{
 void *legacy;
 ssize_t ret;
 size_t;

 ifreturn;
  info("}
  goto legacy;
 }

 info("%s: static voidep0_init(struct thread*t, bool legacy_descriptors)
 ret = write(t->fd, &descriptors, sizeof descriptors);

 if{
  warn("%s: new format rejected, trying legacy\ void*legacy;
legacy
  len= escs_to_legacylegacy&);
  if (len) {
   ret (legacy_descriptors{
   free(legacy);
  }
 }
 die_on < 0,"s : descriptors" t->);

 info("%sjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 ret = write(t->fd, &stringsret  (t-fd,&, sizeof descriptors);
 die_on(ret < 0, "%s: write: strings", t->filenamejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}


/******************** Main **************************************************/legacy:

int main(int argc, char **argv)
{
bool legacy_descriptors;
unsigned i;

legacy_descriptors = argc > 2 && !strcmp(argv[1], "-l");

init_thread(threads);
ep0_init(threads, legacy_descriptors);

for (i = 1; i < sizeof threads / sizeof *threads; ++i)
init_thread(threads + i);

for (i = 1; i < sizeof threads / sizeof *threads; ++i)
start_thread(threads + i);

start_thread_helper(threads);

for (i = 1; i < sizeof threads / sizeof *threads; ++i)
join_thread(threads + i);

return 0;
}

Messung V0.5
C=92 H=93 G=92

¤ Dauer der Verarbeitung: 0.5 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.