libgphoto2 photo camera library (libgphoto2) Internals  2.5.23
gphoto2-port.c
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
26 #define _DEFAULT_SOURCE
27 
28 #include "config.h"
29 
30 #include <stdarg.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 
35 #include <ltdl.h>
36 
40 
41 #include "gphoto2-port-info.h"
42 
43 #ifdef ENABLE_NLS
44 # include <libintl.h>
45 # undef _
46 # define _(String) dgettext (GETTEXT_PACKAGE, String)
47 # ifdef gettext_noop
48 # define N_(String) gettext_noop (String)
49 # else
50 # define N_(String) (String)
51 # endif
52 #else
53 # define _(String) (String)
54 # define N_(String) (String)
55 # define ngettext(String1,String2,Count) ((Count==1)?String1:String2)
56 #endif
57 
58 #define CHECK_RESULT(result) {int r=(result); if (r<0) return (r);}
59 #define CHECK_SUPP(p,t,o) {if (!(o)) {gp_port_set_error ((p), _("The operation '%s' is not supported by this device"), (t)); return (GP_ERROR_NOT_SUPPORTED);}}
60 #define CHECK_INIT(p) {if (!(p)->pc->ops) {gp_port_set_error ((p), _("The port has not yet been initialized")); return (GP_ERROR_BAD_PARAMETERS);}}
61 
62 #define LOG_DATA(DATA, SIZE, EXPECTED, MSG_PRE, MSG_POST, ...) \
63  if (SIZE != EXPECTED) \
64  GP_LOG_DATA (DATA, SIZE, MSG_PRE " %i = 0x%x out of %i bytes " MSG_POST, SIZE, SIZE, EXPECTED, ##__VA_ARGS__); \
65  else \
66  GP_LOG_DATA (DATA, SIZE, MSG_PRE " %i = 0x%x bytes " MSG_POST, SIZE, SIZE, ##__VA_ARGS__)
67 
68 
74  char error[2048];
76  struct _GPPortInfo info;
78  lt_dlhandle lh;
79 };
80 
93 int
95 {
96  C_PARAMS (port);
97 
98  GP_LOG_D ("Creating new device...");
99 
100  C_MEM (*port = calloc (1, sizeof (GPPort)));
101 
102  (*port)->pc = calloc (1, sizeof (GPPortPrivateCore));
103  if (!(*port)->pc) {
104  gp_port_free (*port);
105  return (GP_ERROR_NO_MEMORY);
106  }
107 
108  return (GP_OK);
109 }
110 
111 static int
113 {
114  C_PARAMS (port);
115  CHECK_INIT (port);
116 
117  if (port->pc->ops->init)
118  CHECK_RESULT (port->pc->ops->init (port));
119 
120  return (GP_OK);
121 }
122 
123 static int
125 {
126  C_PARAMS (port);
127  CHECK_INIT (port);
128 
129  if (port->pc->ops->exit)
130  CHECK_RESULT (port->pc->ops->exit (port));
131 
132  return (GP_OK);
133 }
134 
148 int
150 {
151  int ret;
152 
153  GPPortLibraryOperations ops_func;
154 
155  C_PARAMS (port);
156 
157  free (port->pc->info.name);
158  C_MEM (port->pc->info.name = strdup (info->name));
159  free (port->pc->info.path);
160  C_MEM (port->pc->info.path = strdup (info->path));
161  port->pc->info.type = info->type;
162  free (port->pc->info.library_filename);
163  C_MEM (port->pc->info.library_filename = strdup (info->library_filename));
164 
165  port->type = info->type;
166 
167  /* Clean up */
168  if (port->pc->ops) {
169  gp_port_exit (port);
170  free (port->pc->ops);
171  port->pc->ops = NULL;
172  }
173  if (port->pc->lh) {
174 #if !defined(VALGRIND)
175  lt_dlclose (port->pc->lh);
176  lt_dlexit ();
177 #endif
178  }
179 
180  lt_dlinit ();
181  port->pc->lh = lt_dlopenext (info->library_filename);
182  if (!port->pc->lh) {
183  GP_LOG_E ("Could not load '%s' ('%s').", info->library_filename, lt_dlerror ());
184  lt_dlexit ();
185  return (GP_ERROR_LIBRARY);
186  }
187 
188  /* Load the operations */
189  ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations");
190  if (!ops_func) {
191  GP_LOG_E ("Could not find 'gp_port_library_operations' in '%s' ('%s')",
192  info->library_filename, lt_dlerror ());
193  lt_dlclose (port->pc->lh);
194  lt_dlexit ();
195  port->pc->lh = NULL;
196  return (GP_ERROR_LIBRARY);
197  }
198  port->pc->ops = ops_func ();
199  gp_port_init (port);
200 
201  /* Initialize the settings to some default ones */
202  switch (info->type) {
203  case GP_PORT_SERIAL:
204  port->settings.serial.speed = 0;
205  port->settings.serial.bits = 8;
206  port->settings.serial.parity = 0;
207  port->settings.serial.stopbits = 1;
208  gp_port_set_timeout (port, 500);
209  break;
210  case GP_PORT_USB:
211  if (sizeof (port->settings.usb.port) <= strlen(info->path)) {
212  GP_LOG_E ("Path is too long for static buffer '%s'.", info->path);
213  return GP_ERROR_LIBRARY;
214  }
215  strncpy (port->settings.usb.port, info->path,
216  sizeof (port->settings.usb.port));
217  port->settings.usb.inep = -1;
218  port->settings.usb.outep = -1;
219  port->settings.usb.config = -1;
220  port->settings.usb.interface = 0;
221  port->settings.usb.altsetting = -1;
222  gp_port_set_timeout (port, 5000);
223  break;
225  snprintf(port->settings.usbdiskdirect.path,
226  sizeof(port->settings.usbdiskdirect.path), "%s",
227  strchr(info->path, ':') + 1);
228  break;
229  case GP_PORT_USB_SCSI:
230  snprintf(port->settings.usbscsi.path,
231  sizeof(port->settings.usbscsi.path), "%s",
232  strchr(info->path, ':') + 1);
233  break;
234  default:
235  /* Nothing in here */
236  break;
237  }
238  ret = gp_port_set_settings (port, port->settings);
239  if (ret != GP_ERROR_NOT_SUPPORTED)
240  CHECK_RESULT (ret);
241 
242  return GP_OK;
243 }
244 
254 int
256 {
257  C_PARAMS (port && info);
258 
259  *info = &port->pc->info;
260  return (GP_OK);
261 }
262 
272 int
274 {
275  C_PARAMS (port);
276  CHECK_INIT (port);
277 
278  GP_LOG_D ("Opening %s port...",
279  port->type == GP_PORT_SERIAL ? "SERIAL" : (port->type == GP_PORT_USB ? "USB" : ""));
280 
281  CHECK_SUPP (port, "open", port->pc->ops->open);
282  CHECK_RESULT (port->pc->ops->open (port));
283 
284  return GP_OK;
285 }
286 
296 int
298 {
299  GP_LOG_D ("Closing port...");
300 
301  C_PARAMS (port);
302  CHECK_INIT (port);
303 
304  CHECK_SUPP (port, "close", port->pc->ops->close);
305  CHECK_RESULT (port->pc->ops->close(port));
306 
307  return (GP_OK);
308 }
309 
318 int
320 {
321  GP_LOG_D ("Resetting port...");
322 
323  C_PARAMS (port);
324  CHECK_INIT (port);
325 
326  CHECK_SUPP (port, "reset", port->pc->ops->reset);
327  CHECK_RESULT (port->pc->ops->reset(port));
328 
329  return (GP_OK);
330 }
331 
340 int
342 {
343  GP_LOG_D ("Freeing port...");
344 
345  C_PARAMS (port);
346 
347  if (port->pc) {
348  if (port->pc->ops) {
349 
350  /* We don't care for return values */
351  gp_port_close (port);
352  gp_port_exit (port);
353 
354  free (port->pc->ops);
355  port->pc->ops = NULL;
356  }
357 
358  if (port->pc->lh) {
359 #if !defined(VALGRIND)
360  lt_dlclose (port->pc->lh);
361  lt_dlexit ();
362 #endif
363  port->pc->lh = NULL;
364  }
365 
366  free (port->pc->info.name);
367  free (port->pc->info.path);
368  free (port->pc->info.library_filename);
369 
370  free (port->pc);
371  port->pc = NULL;
372  }
373 
374  free (port);
375 
376  return GP_OK;
377 }
378 
391 int
392 gp_port_write (GPPort *port, const char *data, int size)
393 {
394  int retval;
395 
396  gp_log (GP_LOG_DATA, __func__, "Writing %i = 0x%x bytes to port...", size, size);
397 
398  C_PARAMS (port && data);
399  CHECK_INIT (port);
400 
401  /* Check if we wrote all bytes */
402  CHECK_SUPP (port, "write", port->pc->ops->write);
403  retval = port->pc->ops->write (port, data, size);
404  if (retval < 0) {
405  GP_LOG_E ("Writing %i = 0x%x bytes to port failed: %s (%d)",
406  size, size, gp_port_result_as_string(retval), retval);
407  return retval;
408  }
409  LOG_DATA (data, retval, size, "Wrote ", "to port:");
410 
411  return (retval);
412 }
413 
426 int
427 gp_port_read (GPPort *port, char *data, int size)
428 {
429  int retval;
430 
431  gp_log (GP_LOG_DATA, __func__, "Reading %i = 0x%x bytes from port...", size, size);
432 
433  C_PARAMS (port);
434  CHECK_INIT (port);
435 
436  /* Check if we read as many bytes as expected */
437  CHECK_SUPP (port, "read", port->pc->ops->read);
438  retval = port->pc->ops->read (port, data, size);
439  if (retval < 0) {
440  GP_LOG_E ("Reading %i = 0x%x bytes from port failed: %s (%d)",
441  size, size, gp_port_result_as_string(retval), retval);
442  return retval;
443  }
444  LOG_DATA (data, retval, size, "Read ", "from port:");
445 
446  return (retval);
447 }
448 
462 int
463 gp_port_check_int (GPPort *port, char *data, int size)
464 {
465  int retval;
466 
467  gp_log (GP_LOG_DATA, __func__, "Reading %i = 0x%x bytes from interrupt endpoint...", size, size);
468 
469  C_PARAMS (port);
470  CHECK_INIT (port);
471 
472  /* Check if we read as many bytes as expected */
473  CHECK_SUPP (port, "check_int", port->pc->ops->check_int);
474  retval = port->pc->ops->check_int (port, data, size, port->timeout);
475  CHECK_RESULT (retval);
476  LOG_DATA (data, retval, size, "Read ", "from interrupt endpoint:");
477 
478  return (retval);
479 }
480 
482 #define FAST_TIMEOUT 50
483 
495 int
496 gp_port_check_int_fast (GPPort *port, char *data, int size)
497 {
498  int retval;
499 
500  gp_log (GP_LOG_DATA, __func__, "Reading %i = 0x%x bytes from interrupt endpoint...", size, size);
501 
502  C_PARAMS (port);
503  CHECK_INIT (port);
504 
505  /* Check if we read as many bytes as expected */
506  CHECK_SUPP (port, "check_int", port->pc->ops->check_int);
507  retval = port->pc->ops->check_int (port, data, size, FAST_TIMEOUT);
508  CHECK_RESULT (retval);
509 
510 #ifdef IGNORE_EMPTY_INTR_READS
511  /* For Canon cameras, we will make lots of
512  reads that will return zero length. Don't
513  bother to log them as errors. */
514  if (retval != 0 )
515 #endif
516  LOG_DATA (data, retval, size, "Read ", "from interrupt endpoint (fast):");
517 
518  return (retval);
519 }
520 
521 
533 int
534 gp_port_set_timeout (GPPort *port, int timeout)
535 {
536  C_PARAMS (port);
537 
538  GP_LOG_D ("Setting port timeout to %i milliseconds.", timeout);
539  port->timeout = timeout;
540 
541  return GP_OK;
542 }
543 
545 int gp_port_timeout_set (GPPort *, int);
546 int gp_port_timeout_set (GPPort *port, int timeout)
547 {
548  return (gp_port_set_timeout (port, timeout));
549 }
550 
552 int gp_port_timeout_get (GPPort *, int *);
553 int gp_port_timeout_get (GPPort *port, int *timeout)
554 {
555  return (gp_port_get_timeout (port, timeout));
556 }
557 
567 int
568 gp_port_get_timeout (GPPort *port, int *timeout)
569 {
570  C_PARAMS (port);
571 
572  GP_LOG_D ("Current port timeout is %i milliseconds.", port->timeout);
573  *timeout = port->timeout;
574 
575  return GP_OK;
576 }
577 
589 int
591 {
592  GP_LOG_D ("Setting settings...");
593 
594  C_PARAMS (port);
595  CHECK_INIT (port);
596 
597  /*
598  * We copy the settings to settings_pending and call update on the
599  * port.
600  */
601  memcpy (&port->settings_pending, &settings,
602  sizeof (port->settings_pending));
603  CHECK_SUPP (port, "update", port->pc->ops->update);
604  CHECK_RESULT (port->pc->ops->update (port));
605 
606  return (GP_OK);
607 }
608 
612 {
613  return (gp_port_get_settings (port, settings));
614 }
618 {
619  return (gp_port_set_settings (port, settings));
620 }
621 
631 int
633 {
634  C_PARAMS (port);
635 
636  memcpy (settings, &(port->settings), sizeof (gp_port_settings));
637 
638  return GP_OK;
639 }
640 
650 int
652 {
653  GP_LOG_D ("Getting level of pin %i...", pin);
654 
655  C_PARAMS (port && level);
656  CHECK_INIT (port);
657 
658  CHECK_SUPP (port, "get_pin", port->pc->ops->get_pin);
659  CHECK_RESULT (port->pc->ops->get_pin (port, pin, level));
660 
661  GP_LOG_D ("Level of pin %i: %i", pin, *level);
662 
663  return (GP_OK);
664 }
665 
666 static struct {
668  unsigned char number;
669  const char *description_short;
670  const char *description_long;
671 } PinTable[] = {
672  /* we do not translate these technical terms ... for now */
673  {GP_PIN_RTS , 7, "RTS" , "Request To Send" },
674  {GP_PIN_DTR , 4, "DTR" , "Data Terminal Ready"},
675  {GP_PIN_CTS , 8, "CTS" , "Clear To Send" },
676  {GP_PIN_DSR , 6, "DSR" , "Data Set Ready" },
677  {GP_PIN_CD , 1, "CD" , "Carrier Detect" },
678  {GP_PIN_RING, 9, "RING", "Ring Indicator" },
679  {0, 0, NULL, NULL}
680 };
681 
682 static struct {
684  const char *description;
685 } LevelTable[] = {
686  {GP_LEVEL_LOW, N_("low")},
687  {GP_LEVEL_HIGH, N_("high")},
688  {0, NULL}
689 };
690 
702 int
704 {
705  unsigned int i, j;
706 
707  for (i = 0; PinTable[i].description_short; i++)
708  if (PinTable[i].pin == pin)
709  break;
710  for (j = 0; LevelTable[j].description; j++)
711  if (LevelTable[j].level == level)
712  break;
713  GP_LOG_D ("Setting pin %i (%s: '%s') to '%s'...",
716 
717  C_PARAMS (port);
718  CHECK_INIT (port);
719 
720  CHECK_SUPP (port, "set_pin", port->pc->ops->set_pin);
721  CHECK_RESULT (port->pc->ops->set_pin (port, pin, level));
722 
723  return (GP_OK);
724 }
725 
736 int
737 gp_port_send_break (GPPort *port, int duration)
738 {
739  GP_LOG_D ("Sending break (%i milliseconds)...", duration);
740 
741  C_PARAMS (port);
742  CHECK_INIT (port);
743 
744  CHECK_SUPP (port, "send_break", port->pc->ops->send_break);
745  CHECK_RESULT (port->pc->ops->send_break (port, duration));
746 
747  return (GP_OK);
748 }
749 
761 int
762 gp_port_flush (GPPort *port, int direction)
763 {
764  GP_LOG_D ("Flushing port...");
765 
766  C_PARAMS (port);
767 
768  CHECK_SUPP (port, "flush", port->pc->ops->flush);
769  CHECK_RESULT (port->pc->ops->flush (port, direction));
770 
771  return (GP_OK);
772 }
773 
774 
775 /* USB-specific functions */
776 /* ------------------------------------------------------------------ */
777 
789 int
790 gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
791 {
792  C_PARAMS (port);
793  CHECK_INIT (port);
794 
795  CHECK_SUPP (port, "find_device", port->pc->ops->find_device);
796  CHECK_RESULT (port->pc->ops->find_device (port, idvendor, idproduct));
797 
798  return (GP_OK);
799 }
800 
813 int
814 gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol)
815 {
816  C_PARAMS (port);
817  CHECK_INIT (port);
818 
819  CHECK_SUPP (port, "find_device_by_class", port->pc->ops->find_device_by_class);
820  CHECK_RESULT (port->pc->ops->find_device_by_class (port, mainclass, subclass, protocol));
821 
822  return (GP_OK);
823 }
824 
835 int
837 {
838  GP_LOG_D ("Clear USB halt...");
839 
840  C_PARAMS (port);
841  CHECK_INIT (port);
842 
843  CHECK_SUPP (port, "clear_halt", port->pc->ops->clear_halt);
844  CHECK_RESULT (port->pc->ops->clear_halt (port, ep));
845 
846  return (GP_OK);
847 }
848 
863 int
864 gp_port_usb_msg_write (GPPort *port, int request, int value, int index,
865  char *bytes, int size)
866 {
867  int retval;
868 
869  GP_LOG_DATA (bytes, size, "Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x):",
870  request, value, index, size, size);
871 
872  C_PARAMS (port);
873  CHECK_INIT (port);
874 
875  CHECK_SUPP (port, "msg_write", port->pc->ops->msg_write);
876  retval = port->pc->ops->msg_write(port, request, value, index, bytes, size);
877  CHECK_RESULT (retval);
878 
879  return (retval);
880 }
881 
896 int
897 gp_port_usb_msg_read (GPPort *port, int request, int value, int index,
898  char *bytes, int size)
899 {
900  int retval;
901 
902  gp_log (GP_LOG_DATA, __func__, "Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
903  request, value, index, size, size);
904 
905  C_PARAMS (port);
906  CHECK_INIT (port);
907 
908  CHECK_SUPP (port, "msg_read", port->pc->ops->msg_read);
909  retval = port->pc->ops->msg_read (port, request, value, index, bytes, size);
910  CHECK_RESULT (retval);
911 
912  LOG_DATA (bytes, retval, size, "Read", "USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
913  request, value, index, size, size);
914 
915  return (retval);
916 }
917 
918 /*
919  * The next two functions handle the request types 0x41 for write
920  * and 0xc1 for read.
921  */
936 int
938  int value, int index, char *bytes, int size)
939 {
940  int retval;
941 
942  GP_LOG_DATA (bytes, size, "Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
943  request, value, index, size, size);
944 
945  C_PARAMS (port);
946  CHECK_INIT (port);
947 
948  CHECK_SUPP (port, "msg_build", port->pc->ops->msg_interface_write);
949  retval = port->pc->ops->msg_interface_write(port, request,
950  value, index, bytes, size);
951  CHECK_RESULT (retval);
952 
953  return (retval);
954 }
955 
956 
971 int
972 gp_port_usb_msg_interface_read (GPPort *port, int request, int value, int index,
973  char *bytes, int size)
974 {
975  int retval;
976 
977  gp_log (GP_LOG_DATA, __func__, "Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
978  request, value, index, size, size);
979 
980  C_PARAMS (port);
981  CHECK_INIT (port);
982 
983  CHECK_SUPP (port, "msg_read", port->pc->ops->msg_interface_read);
984  retval = port->pc->ops->msg_interface_read (port, request,
985  value, index, bytes, size);
986  CHECK_RESULT (retval);
987 
988  LOG_DATA (bytes, retval, size, "Read", "USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
989  request, value, index, size, size);
990 
991  return (retval);
992 }
993 
994 
995 /*
996  * The next two functions handle the request types 0x21 for write
997  * and 0xa1 for read.
998  */
999 
1014 int
1016  int value, int index, char *bytes, int size)
1017 {
1018  int retval;
1019 
1020  GP_LOG_DATA (bytes, size, "Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x):",
1021  request, value, index, size, size);
1022 
1023  C_PARAMS (port);
1024  CHECK_INIT (port);
1025 
1026  CHECK_SUPP (port, "msg_build", port->pc->ops->msg_class_write);
1027  retval = port->pc->ops->msg_class_write(port, request,
1028  value, index, bytes, size);
1029  CHECK_RESULT (retval);
1030 
1031  return (retval);
1032 }
1033 
1034 
1049 int
1050 gp_port_usb_msg_class_read (GPPort *port, int request, int value, int index,
1051  char *bytes, int size)
1052 {
1053  int retval;
1054 
1055  gp_log (GP_LOG_DATA, __func__, "Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
1056  request, value, index, size, size);
1057 
1058  C_PARAMS (port);
1059  CHECK_INIT (port);
1060 
1061  CHECK_SUPP (port, "msg_read", port->pc->ops->msg_class_read);
1062  retval = port->pc->ops->msg_class_read (port, request,
1063  value, index, bytes, size);
1064  CHECK_RESULT (retval);
1065 
1066  LOG_DATA (bytes, retval, size, "Read", "USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
1067  request, value, index, size, size);
1068 
1069  return (retval);
1070 }
1071 
1083 int
1084 gp_port_seek (GPPort *port, int offset, int whence)
1085 {
1086  int retval;
1087 
1088  GP_LOG_D ("Seeking to: %d whence: %d", offset, whence);
1089 
1090  C_PARAMS (port);
1091  CHECK_INIT (port);
1092 
1093  CHECK_SUPP (port, "seek", port->pc->ops->seek);
1094  retval = port->pc->ops->seek (port, offset, whence);
1095 
1096  GP_LOG_D ("Seek result: %d", retval);
1097 
1098  return retval;
1099 }
1100 
1118 int gp_port_send_scsi_cmd (GPPort *port, int to_dev,
1119  char *cmd, int cmd_size,
1120  char *sense, int sense_size,
1121  char *data, int data_size)
1122 {
1123  int retval;
1124 
1125  GP_LOG_DATA (cmd, cmd_size, "Sending scsi cmd:");
1126  if (to_dev && data_size)
1127  GP_LOG_DATA (data, data_size, "with scsi cmd data:");
1128 
1129  C_PARAMS (port);
1130  CHECK_INIT (port);
1131 
1132  memset (sense, 0, sense_size);
1133  CHECK_SUPP (port, "send_scsi_cmd", port->pc->ops->send_scsi_cmd);
1134  retval = port->pc->ops->send_scsi_cmd (port, to_dev, cmd, cmd_size,
1135  sense, sense_size, data, data_size);
1136 
1137  GP_LOG_D ("scsi cmd result: %d", retval);
1138 
1139  if (sense[0] != 0) {
1140  GP_LOG_DATA (sense, sense_size, "sense data:");
1141  /* https://secure.wikimedia.org/wikipedia/en/wiki/Key_Code_Qualifier */
1142  GP_LOG_D ("sense decided:");
1143  if ((sense[0]&0x7f)!=0x70) {
1144  GP_LOG_D ("\tInvalid header.");
1145  }
1146  GP_LOG_D ("\tCurrent command read filemark: %s",(sense[2]&0x80)?"yes":"no");
1147  GP_LOG_D ("\tEarly warning passed: %s",(sense[2]&0x40)?"yes":"no");
1148  GP_LOG_D ("\tIncorrect blocklengt: %s",(sense[2]&0x20)?"yes":"no");
1149  GP_LOG_D ("\tSense Key: %d",sense[2]&0xf);
1150  if (sense[0]&0x80)
1151  GP_LOG_D ("\tResidual Length: %d",sense[3]*0x1000000+sense[4]*0x10000+sense[5]*0x100+sense[6]);
1152  GP_LOG_D ("\tAdditional Sense Length: %d",sense[7]);
1153  GP_LOG_D ("\tAdditional Sense Code: %d",sense[12]);
1154  GP_LOG_D ("\tAdditional Sense Code Qualifier: %d",sense[13]);
1155  if (sense[15]&0x80) {
1156  GP_LOG_D ("\tIllegal Param is in %s",(sense[15]&0x40)?"the CDB":"the Data Out Phase");
1157  if (sense[15]&0x8) {
1158  GP_LOG_D ("Pointer at %d, bit %d",sense[16]*256+sense[17],sense[15]&0x7);
1159  }
1160  }
1161  }
1162 
1163  if (!to_dev && data_size)
1164  GP_LOG_DATA (data, data_size, "scsi cmd data:");
1165 
1166  return retval;
1167 }
1168 
1179 int
1180 gp_port_set_error (GPPort *port, const char *format, ...)
1181 {
1182  va_list args;
1183 
1184  C_PARAMS (port);
1185 
1186  if (format) {
1187  va_start (args, format);
1188  vsnprintf (port->pc->error, sizeof (port->pc->error),
1189  _(format), args);
1190  GP_LOG_E ("%s", port->pc->error);
1191  va_end (args);
1192  } else
1193  port->pc->error[0] = '\0';
1194 
1195  return (GP_OK);
1196 }
1197 
1209 const char *
1211 {
1212  if (port && port->pc && strlen (port->pc->error))
1213  return (port->pc->error);
1214 
1215  return _("No error description available");
1216 }
_GPPortInfo::name
char * name
The name of this port (usb:)
Definition: gphoto2-port-info.h:34
_GPPortInfo
Definition: gphoto2-port-info.h:32
gp_port_usb_msg_write
int gp_port_usb_msg_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB control message with output data.
Definition: gphoto2-port.c:864
gp_port_get_timeout
int gp_port_get_timeout(GPPort *port, int *timeout)
Get the current port timeout.
Definition: gphoto2-port.c:568
_GPPortOperations::msg_interface_read
int(* msg_interface_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:68
gp_port_usb_msg_class_write
int gp_port_usb_msg_class_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB class control message with output data.
Definition: gphoto2-port.c:1015
_GPPortSettingsSerial::parity
GPPortSerialParity parity
Definition: gphoto2-port.h:70
_GPPortSettingsUsbScsi::path
char path[128]
Definition: gphoto2-port.h:105
CHECK_SUPP
#define CHECK_SUPP(p, t, o)
Definition: gphoto2-port.c:59
_GPPortOperations::open
int(* open)(GPPort *)
Definition: gphoto2-port-library.h:42
CHECK_RESULT
#define CHECK_RESULT(result)
Definition: gphoto2-port.c:58
GP_PIN_DTR
@ GP_PIN_DTR
DTR line.
Definition: gphoto2-port.h:186
gp_port_check_int
int gp_port_check_int(GPPort *port, char *data, int size)
Check for intterupt.
Definition: gphoto2-port.c:463
_GPPortInfo::type
GPPortType type
The type of this port.
Definition: gphoto2-port-info.h:33
GP_LOG_DATA
@ GP_LOG_DATA
Log message is a data hex dump.
Definition: gphoto2-port-log.h:34
level
GPLevel level
Definition: gphoto2-port.c:683
gp_port_set_error
int gp_port_set_error(GPPort *port, const char *format,...)
Set verbose port error message.
Definition: gphoto2-port.c:1180
_GPPortOperations::send_break
int(* send_break)(GPPort *, int)
Definition: gphoto2-port-library.h:55
gp_port_usb_msg_read
int gp_port_usb_msg_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB control message with input data.
Definition: gphoto2-port.c:897
gp_port_get_info
int gp_port_get_info(GPPort *port, GPPortInfo *info)
Retreives information about the port.
Definition: gphoto2-port.c:255
gp_port_seek
int gp_port_seek(GPPort *port, int offset, int whence)
Seek on a port (for usb disk direct ports)
Definition: gphoto2-port.c:1084
number
unsigned char number
Definition: gphoto2-port.c:668
_GPPortOperations::write
int(* write)(GPPort *, const char *, int)
Definition: gphoto2-port-library.h:46
gp_port_close
int gp_port_close(GPPort *port)
Close a port.
Definition: gphoto2-port.c:297
_GPPortSettings::usbdiskdirect
GPPortSettingsUsbDiskDirect usbdiskdirect
usb disk direct port specific settings
Definition: gphoto2-port.h:117
gp_port_send_scsi_cmd
int gp_port_send_scsi_cmd(GPPort *port, int to_dev, char *cmd, int cmd_size, char *sense, int sense_size, char *data, int data_size)
Send a SCSI command to a port (for usb scsi ports)
Definition: gphoto2-port.c:1118
_GPPortOperations::set_pin
int(* set_pin)(GPPort *, GPPin, GPLevel)
Definition: gphoto2-port-library.h:54
gp_port_write
int gp_port_write(GPPort *port, const char *data, int size)
Writes a specified amount of data to a port.
Definition: gphoto2-port.c:392
_GPPortPrivateCore::lh
lt_dlhandle lh
Definition: gphoto2-port.c:78
_GPPort::pc
GPPortPrivateCore * pc
Port library private data pointer.
Definition: gphoto2-port.h:153
gp_port_usb_msg_interface_read
int gp_port_usb_msg_interface_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB interface control message with input data.
Definition: gphoto2-port.c:972
_GPPortOperations::msg_class_write
int(* msg_class_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:70
GP_ERROR_NO_MEMORY
#define GP_ERROR_NO_MEMORY
Out of memory.
Definition: gphoto2-port-result.h:42
CHECK_INIT
#define CHECK_INIT(p)
Definition: gphoto2-port.c:60
gp_port_usb_clear_halt
int gp_port_usb_clear_halt(GPPort *port, int ep)
Clear USB endpoint HALT condition.
Definition: gphoto2-port.c:836
gp_port_new
int gp_port_new(GPPort **port)
Create new GPPort.
Definition: gphoto2-port.c:94
gphoto2-port-result.h
gp_port_flush
int gp_port_flush(GPPort *port, int direction)
Flush data on serial port.
Definition: gphoto2-port.c:762
GP_PIN_DSR
@ GP_PIN_DSR
DSR line.
Definition: gphoto2-port.h:188
_GPPortOperations::msg_interface_write
int(* msg_interface_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:66
gp_port_set_info
int gp_port_set_info(GPPort *port, GPPortInfo info)
Configure a port.
Definition: gphoto2-port.c:149
GP_PIN_CTS
@ GP_PIN_CTS
CTS line.
Definition: gphoto2-port.h:187
LOG_DATA
#define LOG_DATA(DATA, SIZE, EXPECTED, MSG_PRE, MSG_POST,...)
Definition: gphoto2-port.c:62
_GPPortPrivateCore::error
char error[2048]
Definition: gphoto2-port.c:74
GP_PIN_RING
@ GP_PIN_RING
RING (Modem) line.
Definition: gphoto2-port.h:190
gp_port_settings_set
int gp_port_settings_set(GPPort *, GPPortSettings)
Definition: gphoto2-port.c:617
_GPPortSettingsUSB::config
int config
USB bConfigurationValue used.
Definition: gphoto2-port.h:82
_GPPort
The GPhoto port structure.
Definition: gphoto2-port.h:143
_GPPortOperations::msg_write
int(* msg_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:62
_GPPort::settings_pending
GPPortSettings settings_pending
Settings to be committed.
Definition: gphoto2-port.h:148
gp_port_usb_find_device_by_class
int gp_port_usb_find_device_by_class(GPPort *port, int mainclass, int subclass, int protocol)
Find USB device by interface class.
Definition: gphoto2-port.c:814
description_long
const char * description_long
Definition: gphoto2-port.c:670
_GPPortSettings::serial
GPPortSettingsSerial serial
Serial specific settings.
Definition: gphoto2-port.h:115
_GPPortOperations::find_device_by_class
int(* find_device_by_class)(GPPort *dev, int class, int subclass, int protocol)
Definition: gphoto2-port-library.h:60
gp_port_get_settings
int gp_port_get_settings(GPPort *port, GPPortSettings *settings)
Get the current port settings.
Definition: gphoto2-port.c:632
_GPPortInfo::path
char * path
The path of this port (usb:001,023)
Definition: gphoto2-port-info.h:35
_GPPortOperations::close
int(* close)(GPPort *)
Definition: gphoto2-port-library.h:43
gp_port_exit
static int gp_port_exit(GPPort *port)
Definition: gphoto2-port.c:124
description_short
const char * description_short
Definition: gphoto2-port.c:669
_GPPortOperations::reset
int(* reset)(GPPort *)
Definition: gphoto2-port-library.h:84
GP_PIN_CD
@ GP_PIN_CD
Carrier Detect line.
Definition: gphoto2-port.h:189
GP_PORT_USB
@ GP_PORT_USB
USB port.
Definition: gphoto2-port-info-list.h:37
_GPPortSettings::usb
GPPortSettingsUSB usb
USB specific settings.
Definition: gphoto2-port.h:116
GP_PORT_USB_SCSI
@ GP_PORT_USB_SCSI
USB Mass Storage raw SCSI port.
Definition: gphoto2-port-info-list.h:41
_GPPortPrivateCore
Internal private libgphoto2_port data. This structure contains private data.
Definition: gphoto2-port.c:73
_
#define _(String)
Definition: gphoto2-port.c:53
_GPPortOperations::msg_read
int(* msg_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:64
_GPPortSettingsUSB::inep
int inep
Bulk IN endpoint used.
Definition: gphoto2-port.h:79
GP_OK
#define GP_OK
Everything is OK.
Definition: gphoto2-port-result.h:30
N_
#define N_(String)
Definition: gphoto2-port.c:54
_GPPortOperations::find_device
int(* find_device)(GPPort *dev, int idvendor, int idproduct)
Definition: gphoto2-port-library.h:59
_GPPortOperations::msg_class_read
int(* msg_class_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
Definition: gphoto2-port-library.h:72
GP_PIN_RTS
@ GP_PIN_RTS
RTS line.
Definition: gphoto2-port.h:185
gp_port_read
int gp_port_read(GPPort *port, char *data, int size)
Read data from port.
Definition: gphoto2-port.c:427
gp_port_usb_msg_interface_write
int gp_port_usb_msg_interface_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB interface control message with output data.
Definition: gphoto2-port.c:937
gp_port_check_int_fast
int gp_port_check_int_fast(GPPort *port, char *data, int size)
Check for interrupt without wait.
Definition: gphoto2-port.c:496
gp_port_init
static int gp_port_init(GPPort *port)
Definition: gphoto2-port.c:112
GP_PORT_USB_DISK_DIRECT
@ GP_PORT_USB_DISK_DIRECT
Direct IO to an usb mass storage device.
Definition: gphoto2-port-info-list.h:40
_GPPortOperations::flush
int(* flush)(GPPort *, int)
Definition: gphoto2-port-library.h:56
pin
GPPin pin
Definition: gphoto2-port.c:667
gphoto2-port-info.h
GPLevel
enum _GPLevel GPLevel
Level to pull specific lines.
PinTable
static struct @2 PinTable[]
LevelTable
static struct @3 LevelTable[]
_GPPortSettingsUSB::outep
int outep
Bulk OUT endpoint used.
Definition: gphoto2-port.h:80
gphoto2-port-library.h
GPPin
enum _GPPin GPPin
Serial pins.
GP_PORT_SERIAL
@ GP_PORT_SERIAL
Serial port.
Definition: gphoto2-port-info-list.h:36
gp_port_settings_get
int gp_port_settings_get(GPPort *, GPPortSettings *)
Definition: gphoto2-port.c:611
_GPPortSettingsUSB::port
char port[64]
USB Portname. Specific to lowlevel USB.
Definition: gphoto2-port.h:91
gp_port_set_settings
int gp_port_set_settings(GPPort *port, GPPortSettings settings)
Set port settings.
Definition: gphoto2-port.c:590
GPPortLibraryOperations
GPPortOperations *(* GPPortLibraryOperations)(void)
Definition: gphoto2-port-library.h:91
_GPPortOperations::init
int(* init)(GPPort *)
Definition: gphoto2-port-library.h:40
gp_port_timeout_set
int gp_port_timeout_set(GPPort *, int)
Definition: gphoto2-port.c:546
_GPPortSettings
Union of port settings.
Definition: gphoto2-port.h:114
_GPPortOperations::seek
int(* seek)(GPPort *dev, int offset, int whence)
Definition: gphoto2-port-library.h:76
_GPPortOperations::read
int(* read)(GPPort *, char *, int)
Definition: gphoto2-port-library.h:44
gp_port_timeout_get
int gp_port_timeout_get(GPPort *, int *)
Definition: gphoto2-port.c:553
GP_LEVEL_HIGH
@ GP_LEVEL_HIGH
Pull to high (nV)
Definition: gphoto2-port.h:200
_GPPortSettings::usbscsi
GPPortSettingsUsbScsi usbscsi
usb scsi port specific settings
Definition: gphoto2-port.h:118
_GPPortPrivateCore::info
struct _GPPortInfo info
Definition: gphoto2-port.c:76
gp_port_send_break
int gp_port_send_break(GPPort *port, int duration)
Send a break over a serial port.
Definition: gphoto2-port.c:737
_GPPortOperations::check_int
int(* check_int)(GPPort *, char *, int, int)
Definition: gphoto2-port-library.h:45
gp_port_set_pin
int gp_port_set_pin(GPPort *port, GPPin pin, GPLevel level)
Set specified serial PIN to value.
Definition: gphoto2-port.c:703
gp_port_open
int gp_port_open(GPPort *port)
Open a port.
Definition: gphoto2-port.c:273
_GPPortOperations::send_scsi_cmd
int(* send_scsi_cmd)(GPPort *port, int to_dev, char *cmd, int cmd_size, char *sense, int sense_size, char *data, int data_size)
Definition: gphoto2-port-library.h:79
GP_LEVEL_LOW
@ GP_LEVEL_LOW
Pull to low (0V)
Definition: gphoto2-port.h:199
gphoto2-port-log.h
gp_port_free
int gp_port_free(GPPort *port)
Free the port structure.
Definition: gphoto2-port.c:341
gp_port_usb_msg_class_read
int gp_port_usb_msg_class_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB class control message with input data.
Definition: gphoto2-port.c:1050
description
const char * description
Definition: gphoto2-port.c:684
_GPPortInfo::library_filename
char * library_filename
Internal pathname of the port driver. Do not use outside of the port library.
Definition: gphoto2-port-info.h:38
_GPPortSettingsUsbDiskDirect::path
char path[128]
Definition: gphoto2-port.h:98
GP_ERROR_LIBRARY
#define GP_ERROR_LIBRARY
Error in the camera driver.
Definition: gphoto2-port-result.h:46
gp_port_set_timeout
int gp_port_set_timeout(GPPort *port, int timeout)
Set timeout of port.
Definition: gphoto2-port.c:534
_GPPortSettingsUSB::altsetting
int altsetting
USB Alternative Setting used.
Definition: gphoto2-port.h:84
_GPPortSettingsSerial::bits
int bits
Definition: gphoto2-port.h:69
FAST_TIMEOUT
#define FAST_TIMEOUT
Definition: gphoto2-port.c:482
_GPPortOperations::clear_halt
int(* clear_halt)(GPPort *dev, int ep)
Definition: gphoto2-port-library.h:61
_GPPort::timeout
int timeout
Port timeout in milliseconds.
Definition: gphoto2-port.h:150
gp_log
void gp_log(GPLogLevel level, const char *domain, const char *format,...)
Log a debug or error message.
Definition: gphoto2-port-log.c:331
_GPPort::settings
GPPortSettings settings
Current port settings.
Definition: gphoto2-port.h:147
_GPPortOperations::exit
int(* exit)(GPPort *)
Definition: gphoto2-port-library.h:41
_GPPortOperations::update
int(* update)(GPPort *)
Definition: gphoto2-port-library.h:47
_GPPortOperations
The port operations.
Definition: gphoto2-port-library.h:39
_GPPortPrivateCore::ops
GPPortOperations * ops
Definition: gphoto2-port.c:77
_GPPort::type
GPPortType type
Actual type of this port.
Definition: gphoto2-port.h:145
_GPPortSettingsSerial::stopbits
int stopbits
Definition: gphoto2-port.h:72
gp_port_get_error
const char * gp_port_get_error(GPPort *port)
Get verbose port error message.
Definition: gphoto2-port.c:1210
gp_port_get_pin
int gp_port_get_pin(GPPort *port, GPPin pin, GPLevel *level)
Get setting of specific serial PIN.
Definition: gphoto2-port.c:651
gp_port_usb_find_device
int gp_port_usb_find_device(GPPort *port, int idvendor, int idproduct)
Find USB device by vendor/product.
Definition: gphoto2-port.c:790
gp_port_reset
int gp_port_reset(GPPort *port)
Reset a port.
Definition: gphoto2-port.c:319
_GPPortSettingsUSB::interface
int interface
USB Interface number used.
Definition: gphoto2-port.h:83
gp_port_result_as_string
const char * gp_port_result_as_string(int result)
Definition: gphoto2-port-result.c:54
GP_ERROR_NOT_SUPPORTED
#define GP_ERROR_NOT_SUPPORTED
Functionality not supported.
Definition: gphoto2-port-result.h:54
_GPPortOperations::get_pin
int(* get_pin)(GPPort *, GPPin, GPLevel *)
Definition: gphoto2-port-library.h:53
_GPPortSettingsSerial::speed
int speed
Definition: gphoto2-port.h:68