@@ -1177,7 +1177,7 @@ char getPortDetails(const char *deviceName, char* portLocation, int* vendorID, i
11771177{
11781178 // Attempt to locate the device in sysctl
11791179 size_t bufferSize = 1024 ;
1180- char * stdOutResult = (char * )malloc (bufferSize ), * deviceLocation = NULL , * deviceInfo = NULL ;
1180+ char * stdOutResult = (char * )malloc (bufferSize ), * deviceLocation = NULL , * deviceInfo = NULL , * driverName = NULL ;
11811181 snprintf (stdOutResult , bufferSize , "sysctl -a | grep \"ttyname: %s\"" , deviceName );
11821182 FILE * pipe = popen (stdOutResult , "r" );
11831183 if (pipe )
@@ -1187,14 +1187,18 @@ char getPortDetails(const char *deviceName, char* portLocation, int* vendorID, i
11871187 deviceLocation = stdOutResult ;
11881188 * (strstr (deviceLocation , "ttyname:" ) - 1 ) = '\0' ;
11891189 deviceInfo = (char * )malloc (strlen (deviceLocation ) + 12 );
1190+ driverName = (char * )malloc (strlen (deviceLocation ) + 12 );
11901191 strcpy (deviceInfo , deviceLocation );
1192+ strcpy (driverName , deviceLocation );
11911193 strcat (deviceLocation , ".%location" );
11921194 strcat (deviceInfo , ".%pnpinfo" );
1195+ strcat (driverName , ".%driver" );
11931196 }
11941197 pclose (pipe );
11951198 }
11961199 strcpy (serialNumber , "Unknown" );
11971200 strcpy (manufacturer , "Unknown" );
1201+ strcpy (deviceDriver , "Unknown" );
11981202
11991203 // Parse port location
12001204 if (deviceLocation )
@@ -1269,12 +1273,32 @@ char getPortDetails(const char *deviceName, char* portLocation, int* vendorID, i
12691273 }
12701274 free (temp );
12711275 }
1272- // TODO: DEVICE DRIVER
1276+
1277+ // Parse device driver
1278+ if (driverName )
1279+ {
1280+ char * temp = (char * )malloc (64 );
1281+ sprintf (temp , "sysctl -a | grep \"%s\"" , driverName );
1282+ pipe = popen (temp , "r" );
1283+ if (pipe )
1284+ {
1285+ while (fgets (stdOutResult , bufferSize , pipe ))
1286+ if (strstr (stdOutResult , ": " ))
1287+ {
1288+ strcpy (deviceDriver , strstr (stdOutResult , ": " ) + 2 );
1289+ break ;
1290+ }
1291+ pclose (pipe );
1292+ }
1293+ free (temp );
1294+ }
12731295
12741296 // Clean up memory and return result
12751297 free (stdOutResult );
12761298 if (deviceInfo )
12771299 free (deviceInfo );
1300+ if (driverName )
1301+ free (driverName );
12781302 return (deviceLocation ? 1 : 0 );
12791303}
12801304
@@ -1389,6 +1413,7 @@ char getUsbPortDetails(const char* usbDeviceFile, char* portLocation, char* frie
13891413 size_t bufferSize = 1024 ;
13901414 strcpy (serialNumber , "Unknown" );
13911415 strcpy (manufacturer , "Unknown" );
1416+ strcpy (deviceDriver , "Unknown" );
13921417 char * stdOutResult = (char * )malloc (bufferSize ), * device = (char * )malloc (64 );
13931418 snprintf (stdOutResult , bufferSize , "dmesg | grep ucom%s | tail -1" , usbDeviceFile + 1 );
13941419 FILE * pipe = popen (stdOutResult , "r" );
@@ -1469,7 +1494,6 @@ char getUsbPortDetails(const char* usbDeviceFile, char* portLocation, char* frie
14691494 }
14701495 free (usbFile );
14711496 }
1472- // TODO: DEVICE DRIVER
14731497
14741498 // Clean up memory and return result
14751499 free (device );
@@ -1700,7 +1724,7 @@ void searchForComPorts(serialPortVector* comPorts)
17001724 }
17011725 }
17021726 else
1703- pushBack (comPorts , comPortCu , friendlyName , friendlyName , portLocation , serialNumber , manufacturer , "TODO " , vendorID , productID , 0 );
1727+ pushBack (comPorts , comPortCu , friendlyName , friendlyName , portLocation , serialNumber , manufacturer , "Unknown " , vendorID , productID , 0 );
17041728
17051729 // Check if dialin port is already enumerated
17061730 port = fetchPort (comPorts , comPortTty );
@@ -1723,7 +1747,7 @@ void searchForComPorts(serialPortVector* comPorts)
17231747 }
17241748 }
17251749 else
1726- pushBack (comPorts , comPortTty , friendlyName , friendlyName , portLocation , serialNumber , manufacturer , "TODO " , vendorID , productID , 0 );
1750+ pushBack (comPorts , comPortTty , friendlyName , friendlyName , portLocation , serialNumber , manufacturer , "Unknown " , vendorID , productID , 0 );
17271751 IOObjectRelease (serialPort );
17281752 }
17291753 IOObjectRelease (serialPortIterator );
0 commit comments