Usb mass storage file system location on QNX - qnx

I need my software to be notifed that usb mass storage stick has been inserterd, also i need locationa where this stick has been mounted. Is it possible to obtain this information, especially location on fs where stick has been mounted from any C library ?
For instertion i already know usbd_connect() and i'm using it. Unfortunatelly there is no information with respect to location on fs.
regards
JosiP

io-usb should be up and running on your target.
Add the library "usbdi" to your project.
Then use the following code snipet :
#include <sys/usbdi.h>
static struct usbd_connection *conn_usb = NULL;
static void cbinsert(struct usbd_connection *connection, usbd_device_instance_t *ins);
static void cbremove(struct usbd_connection *connection, usbd_device_instance_t *ins);
int init(void)
{
usbd_funcs_t funcs = { _USBDI_NFUNCS, cbinsert, cbremove, NULL };
usbd_connect_parm_t parm = {NULL, USB_VERSION, USBD_VERSION, 0, 0, NULL, 0, NULL, &funcs,0};
if (usbd_connect(&parm, &conn_usb) != EOK) {
/* write your own error handler */
}
And then, add your customized handler :
static void cbinsert(struct usbd_connection *usb_connection,usbd_device_instance_t *usb_instance)
{
if (usb_instance->ident.dclass == 8 && usb_instance->ident.subclass == 6) {
/* USB mass storage */
} else if (usb_instance->ident.dclass == 3 && usb_instance->ident.subclass == 1) {
/* USB mouse */
} else {
/* unknown device */
}
This is an example. You will have to customized it.
But everything you need is there.
Hope this help !
Emmanuel

Try using MCD(Media Content Detector) in QNX. Refer to the below links -
http://www.qnx.com/developers/docs/6.4.1/neutrino/utilities/m/mcd.html
http://www.qnx.com/developers/docs/660/index.jsp?topic=%2Fcom.qnx.doc.dev_pub.ref_guide%2Ftopic%2Fdrivers.html

Related

Using WINC1500 with a PIC32, scan not working properly

I'm currently working on a project using a PIC32 and the wifi module ATWINC1500. I won't be able to give all the code but I'm on a test function that I can share.
First, here is some settings and configuration I'm using:
Processor : PIC32MZ1024EFE064
IDE : MPLAB IDE 5.45
Harmony version : 2.06
Wifi Module : ATWINC1500
Real Time OS : FreeRTOS
What I'm trying to do is to connect the Wifi module to an existing Access Point using the Infrastructure mode. I'm able to get the number of access point around me but when I try to read information from those access points, information are empty, void or incorrect.
Here is my code:
bool WIFI_Test_Infrastructure(void)
{
//Example: https://www.microchip.com/forums/m906568.aspx
//Wait for WINC1500 to be initialized
if(isWdrvExtReady() == false)
return false;
//Start a scan or wait for result
IWPRIV_PARAM_SCAN scanner;
IWPRIV_GET_PARAM param_scan = {
.scan = scanner
};
iwpriv_get(SCANSTATUS_GET, &param_scan);
IWPRIV_SCAN_STATUS status = param_scan.scan.scanStatus;
IWPRIV_EXECUTE_PARAM dummy_param;
//Process StateMachine while scanning
if(status == IWPRIV_SCAN_IDLE)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Disconnect wifi from everything
WDRV_Disconnect();
vTaskDelay(1000 / portTICK_PERIOD_MS);
while(WDRV_ConnectionState_Get() != WDRV_CONNECTION_STATE_NOT_CONNECTED)
vTaskDelay(10 / portTICK_PERIOD_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
WDRV_EXT_CmdScanStart();
return false;
}
else if(status == IWPRIV_SCAN_IN_PROGRESS)
{
return false;
}
else if(status == IWPRIV_SCAN_NO_AP_FOUND)
{
iwpriv_execute(SCAN_START, &dummy_param);
return false;
}
else if(status == IWPRIV_SCAN_SUCCESSFUL)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Read liste of wifi access point
uint16_t wifi_number_AP;
wifi_number_AP = m2m_wifi_get_num_ap_found();
WDRV_SCAN_RESULT scanResult;
tstrM2mWifiscanResult result;
int i;
for(i=0; i<wifi_number_AP; i++)
{
m2m_wifi_req_scan_result(i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
winc1500_scan_result_read(&result); //ISSUE HAPPENED HERE
vTaskDelay(1000 / portTICK_PERIOD_MS);
memcpy((void *)scanResult.bssid, (void *)result.au8BSSID, sizeof(scanResult.bssid));
}
//SUCCESS
return true;
}
else
{
return false;
}
}
So what happened here:
First, you need to know that this function is called by a Thread Manager, that's why it returns false or true. I'm checking the state in which the scan is.
I'm able to reach the SCAN_SUCCESSFUL part and the number of access point detected is correct.
I labeled the line where the issue is happening. When I'm reading the result information of an access point, it is quite empty. Here is what I see in Debug Session (and it is the same result for all of access points):
I have been waiting for weeks before asking this. Hope someone can help or at least give me hints on things to check.
If I missed information, do not hesitate to ask me.
Thanks in advance!
Adrien
The solution was simply a story of stack. I have two other tasks: SYS and TCP/IP. I needed to increase the size of their stack because they were managing several functions about scanning. So there was an overriding somewhere.

How to get USB Token (Feitian Auto ePass 2003 FIPS USB Token) serial number in UEFI Application?

Developing UEFI Based application for enabling pre-boot authentication using
Feitian Auto ePass 2003 FIPS USB Token. I'm still in the initial stage of the development process.
Now I'm able to fetch Manufacturer, Product Code of the token by using UsbIo->UsbGetDeviceDescriptor protocol. But when I try to find serial number it's throwing an error.
Is there any other way to find the serial number of the USB Token? Please help me on this..
This is my sample code for finding serial number
EFI_USB_DEVICE_DESCRIPTOR DevDesc;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
EFI_USB_CONFIG_DESCRIPTOR ConfigDescriptor;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer = NULL;
BOOLEAN LangFound;
UINTN HandleCount;
UINT8 EndpointNumber;
CHAR16* ManufacturerString = NULL;
CHAR16* ProductString = NULL;
CHAR16* SerialNumber = NULL;
UINT16* LangIDTable;
UINT16 TableSize;
INTN Index;
int index;
unsigned char* device_descriptor, * ccid_descriptor;
EFI_USB_DEVICE_REQUEST DevReq;
UINT32 Status_uint;
Status = gBS->LocateHandleBuffer( ByProtocol,
&gEfiUsbIoProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer );
if (EFI_ERROR(Status)) {
Print(L"ERROR: LocateHandleBuffer.\n");
goto ErrorExit;
}
UINT8 usbIndex;
for (usbIndex = 0; usbIndex < HandleCount; usbIndex++) {
Status = gBS->HandleProtocol( HandleBuffer[usbIndex],
&gEfiUsbIoProtocolGuid,
(VOID**)&UsbIo );
if (EFI_ERROR(Status)) {
Print(L"ERROR: Open UsbIo.\n");
goto ErrorExit;
}
Status = UsbIo->UsbGetDeviceDescriptor( UsbIo, &DevDesc );
if (EFI_ERROR(Status)) {
Print(L"ERROR: UsbGetDeviceDescriptor.\n");
goto ErrorExit;
}
Status = UsbIo->UsbGetConfigDescriptor( UsbIo, &ConfigDescriptor );
if (EFI_ERROR (Status))
{
Print(L"UsbGetConfigDescriptor %d", Status);
goto ErrorExit;
}
Status = UsbIo->UsbGetInterfaceDescriptor( UsbIo, &InterfaceDescriptor );
if (EFI_ERROR (Status)) {
Print(L"ERROR: UsbGetInterfaceDescriptor.\n");
goto ErrorExit;
}
if (InterfaceDescriptor.InterfaceClass != CLASS_CCID) {
continue;
}
Print(L":::::::::::::::::::::: CCID ::::::::::::::::::::::\n");
//
// Get all supported languages.
//
TableSize = 0;
LangIDTable = NULL;
Status = UsbIo->UsbGetSupportedLanguages(UsbIo, &LangIDTable, &TableSize);
if (EFI_ERROR(Status)) {
Print(L"ERROR: UsbGetSupportedLanguages.\n");
return Status;
}
/* Get Manufacturer string */
for (Index = 0; Index < TableSize / sizeof(LangIDTable[0]); Index++) {
ManufacturerString = NULL;
Status = UsbIo->UsbGetStringDescriptor(UsbIo,
LangIDTable[Index],
DevDesc.StrManufacturer,
&ManufacturerString);
if (EFI_ERROR(Status) || (ManufacturerString == NULL)) {
continue;
}
Print(L"StrManufacturer ::%s\n", ManufacturerString);
FreePool(ManufacturerString);
break;
}
/* Get Product string */
for (Index = 0; Index < TableSize / sizeof(LangIDTable[0]); Index++) {
ProductString = NULL;
Status = UsbIo->UsbGetStringDescriptor(UsbIo,
LangIDTable[Index],
DevDesc.StrProduct,
&ProductString);
if (EFI_ERROR(Status) || (ProductString == NULL)) {
continue;
}
Print(L"StrProduct ::%s\n", ProductString);
FreePool(ProductString);
break;
}
/* Get Serial string */
for (Index = 0; Index < TableSize / sizeof(LangIDTable[0]); Index++) {
SerialNumber = NULL;
Status = UsbIo->UsbGetStringDescriptor(UsbIo,
LangIDTable[Index],
DevDesc.StrSerialNumber,
&SerialNumber);
if (EFI_ERROR(Status) || (SerialNumber == NULL)) {
Print(L"Error in finding SerialNumber \n");
continue;
}
Print(L"SerialNumber :: %s\n", SerialNumber);
FreePool(SerialNumber);
break;
}
Print(L"usbIndex ::%d\n", usbIndex);
Print(L"IdVendor ::%d\n", DevDesc.IdVendor);
Print(L"IdProduct ::%d\n", DevDesc.IdProduct);
}
Print(L"\n");
FreePool(HandleBuffer);
return Status;
From what I have read, the Feitian Technologies ePass2003 uses an Infineon M7893 or SLE 78CUFX5000PH (M7893-B) security chip.
As you have found out, the serial number for the ePass2003 is not stored in the USB device descriptor but in the security chip.
To obtain chip global data such as OEM information, algorithm support, FIPS mode indicator, RAM size and serial number, the GetData primitive is used. See the M7893 programming guide. if you can obtain access to it.
The driver for ePass2003 in OpenSC is called “epass2003”. The source code is currently available at https://github.com/OpenSC/OpenSC/blob/master/src/libopensc/card-epass2003.c. It has dependencies on OpenSSL and ASN.1 and some non-EDK2 headers, but these are easily worked around.
If all you are looking for is the serial number, it should be fairly easy to write a UEFI application (or driver) to get that information either by studying how the OpenSC ePass2003 driver does it (hint - look at epass2003_get_serialnr or studying the ePass2003 SDK which is available for free from Feitain and elsewhere.
The UEFI 2.5 specification released in April 2015 detailed 2 protocols relating to smart cards, i.e. Smart Card Reader and Smart Card Edge.
typedef struct _EFI_SMART_CARD_READER_PROTOCOL {
EFI_SMART_CARD_READER_CONNECT SCardConnect;
EFI_SMART_CARD_READER_DISCONNECT SCardDisconnect;
EFI_SMART_CARD_READER_STATUS SCardStatus;
EFI_SMART_CARD_READER_TRANSMIT SCardTransmit;
EFI_SMART_CARD_READER_CONTROL SCardControl;
EFI_SMART_CARD_READER_GET_ATTRIB SCardGetAttrib;
} EFI_SMART_CARD_READER_PROTOCOL;
typedef struct _EFI_SMART_CARD_EDGE_PROTOCOL {
EFI_SMART_CARD_EDGE_GET_CONTEXT GetContext;
EFI_SMART_CARD_EDGE_CONNECT Connect;
EFI_SMART_CARD_EDGE_DISCONNECT Disconnect;
EFI_SMART_CARD_EDGE_GET_CSN GetCsn;
EFI_SMART_CARD_EDGE_GET_READER_NAME GetReaderName;
EFI_SMART_CARD_EDGE_VERIFY_PIN VerifyPin;
EFI_SMART_CARD_EDGE_GET_PIN_REMAINING GetPinRemaining;
EFI_SMART_CARD_EDGE_GET_DATA GetData;
EFI_SMART_CARD_EDGE_GET_CREDENTIAL GetCredential;
EFI_SMART_CARD_EDGE_SIGN_DATA SignData;
EFI_SMART_CARD_EDGE_DECRYPT_DATA DecryptData;
EFI_SMART_CARD_EDGE_BUILD_DH_AGREEMENT BuildDHAgreement;
} EFI_SMART_CARD_EDGE_PROTOCOL;
EDK2 does not contain a sample implementation at present. However, you may be interested in the GPL2-licensed sample implementation by Ludovic Rousseau which is available at https://github.com/LudovicRousseau/edk2/tree/SmartCard. The implementation code, which is circa 5 years old and which I have not tested, is at MdeModulePkg/Library/SmartCardReader. Read his blog (https://ludovicrousseau.blogspot.com/) also as he provides useful sample applications also.

Saxon-C CentOS8 Compile

I am trying to evaluate Saxon-C 1.2.1 HE on CentOS8 and installation seems to have gone ok. Trying out the samples by cd samples/cppTests && build64-linux.sh though leads to a myriad of compilation errors to the tune of the following:
../../Saxon.C.API/SaxonProcessor.h:599:32: error: division ‘sizeof (JNINativeMethod*) / sizeof (JNINativeMethod)’ does not compute the number of array elements [-Werror=sizeof-pointer-div]
gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
Before I summarily and trustfully switched off -Werror=sizeof-pointer-div i checked the source code and what's going on there do seem dubious.
bool registerCPPFunction(char * libName, JNINativeMethod * gMethods=NULL){
if(libName != NULL) {
setConfigurationProperty("extc", libName);
}
if(gMethods == NULL && nativeMethodVect.size()==0) {
return false;
} else {
if(gMethods == NULL) {
//copy vector to gMethods
gMethods = new JNINativeMethod[nativeMethodVect.size()];
}
return registerNativeMethods(sxn_environ->env, "com/saxonica/functions/>
gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
}
return false;
}
more specifically sizeof(gMethods) / sizeof(gMethods[0]) would not seem to calculate anything useful by any margin. The intention was probably rather to output some code that would arrive at the same value as nativeMethodVect.size() but seeing this project's source for the very first time i might be mistaking and the division is in fact intentional ?
I am inclined to guess the intention was in fact closer to b than to a in the following example:
#include <cstdio>
struct test
{
int x, y, z;
};
int main()
{
test *a = new test[32], b[32];
printf("%d %d\n", sizeof(a)/sizeof(a[0]), sizeof(b)/sizeof(b[0]));
return 0;
}
which output 0 32 which is expected as the sizeof(a) gives the size of a pointer not the size of an array's memory region.
That bit of code is to support the feature of user defined extension functions in XSLT stylesheets and XQuery queries. If a user is not using these features then they don't need that bit of code. In fact User defined extension functions is only available in Saxon-PE/C and Saxon-EE/C so it should not be in the Saxon-HE/C code base. I have created the following bug issue to investigate the error above and to https://saxonica.plan.io/issues/4477
I would think the workaround would be to either remove the code in question if the extension function feature is not used or remove the compile flag -Werror=sizeof-pointer-div.
The intent was code is as follows:
jobject JNICALL cppNativeCall(jstring funcName, jobjectArray arguments, jobjectArray argTypes){
//native call code here
}
JNINativeMethod cppMethods[] =
{
{
fname,
funcParameters,
(void *)&cppNativeCall
}
};
bool nativeFound = processor->registerNativeMethods(env, "NativeCall",
cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));

Why does this device_create() call not create a /dev/ entry?

I'm porting platform driver code to a PCIe variant and I don't understand why I'm not getting a /dev/ entry to show up. The platform driver code that has been modified:
static dev_t first;
static struct class * class;
ATTRIBUTE_GROUPS(my);
static int __init my_pci_init(void)
{
int ret;
/* Create a class entry in sysfs */
if ((class = class_create(THIS_MODULE, "test_driver")) == NULL) {
pr_err("Couldn't create 'struct class' structure.");
ret = -ENODEV;
goto exit;
}
class->dev_groups = my_groups;
/* Create the /dev/ file system entry */
/* return value ignored: there's a 'struct class' to 'struct device' mapping */
if (device_create(class, NULL, first, NULL, KBUILD_MODNAME) == NULL) {
pr_err("Couldn't create entry in '/dev/' file system.");
ret = -ENODEV;
goto exit;
} else {
pr_info("Created a /dev/ entry.");
}
if ((ret = pci_register_driver(&pci_driver)) < 0) {
pr_err("Couldn't register pci driver.");
}
exit:
if (ret < 0) {
my_pci_exit();
pr_err(" ret = %d", ret);
}
return ret;
}
module_init(my_pci_init);
If the module name is 'cz_tdm', I was hoping the above code would create an entry /dev/cz_tdm. At least it did when I was compiling this as a platform driver.
The driver enumerates just fine, an output of lspci shows that the driver was loaded and perusing the sysfs shows that all my attributes in /sys/devices/virtual/... are where I'd expect them to be.
What gives?
Whoops.
Because it's not supposed too. An overzealous deletion of code ripped out this necessary element:
/* Add the char device to the system. */
cdev_init(&cdev, &fops);
if ((ret = cdev_add(&cdev, first, DEV_MINOR_NUMBER_COUNT)) < 0) {
pr_err("Couldn't add device to system: %d", ret);
ret = -ENODEV;
goto exit;
}

Play a Video from MemoryStream, Using FFMpeg

I'm having a hard time, searching how to play a video file from a TMemoryStream (or a similar buffer in memory) using FFMpeg. I've seen many things, including UltraStarDX, expensive FFMpeg components for Delphi and so on.
One component called FFMpeg Vcl Player claims to play video formats from a memory stream. I downloaded the trial version and I guess it uses CircularBuffer.pas for that matter (maybe).
Does any one know how to do this?
Edit:
Now the better question is how to play an encrypted video file, using FFMpeg or similar libraries.
To play video from memory stream, you can use custom AVIOContext.
static const int kBufferSize = 4 * 1024;
class my_iocontext_private
{
private:
my_iocontext_private(my_iocontext_private const &);
my_iocontext_private& operator = (my_iocontext_private const &);
public:
my_iocontext_private(IInputStreamPtr inputStream)
: inputStream_(inputStream)
, buffer_size_(kBufferSize)
, buffer_(static_cast<unsigned char*>(::av_malloc(buffer_size_))) {
ctx_ = ::avio_alloc_context(buffer_, buffer_size_, 0, this,
&my_iocontext_private::read, NULL, &my_iocontext_private::seek);
}
~my_iocontext_private() {
::av_free(ctx_);
::av_free(buffer_);
}
void reset_inner_context() { ctx_ = NULL; buffer_ = NULL; }
static int read(void *opaque, unsigned char *buf, int buf_size) {
my_iocontext_private* h = static_cast<my_iocontext_private*>(opaque);
return h->inputStream_->Read(buf, buf_size);
}
static int64_t seek(void *opaque, int64_t offset, int whence) {
my_iocontext_private* h = static_cast<my_iocontext_private*>(opaque);
if (0x10000 == whence)
return h->inputStream_->Size();
return h->inputStream_->Seek(offset, whence);
}
::AVIOContext *get_avio() { return ctx_; }
private:
IInputStreamPtr inputStream_; // abstract stream interface, You can adapt it to TMemoryStream
int buffer_size_;
unsigned char * buffer_;
::AVIOContext * ctx_;
};
//// ..........
/// prepare input stream:
IInputStreamPtr inputStream = MyCustomCreateInputStreamFromMemory();
my_iocontext_private priv_ctx(inputStream);
AVFormatContext * ctx = ::avformat_alloc_context();
ctx->pb = priv_ctx.get_avio();
int err = avformat_open_input(&ctx, "arbitrarytext", NULL, NULL);
if (err < 0)
return -1;
//// normal usage of ctx
//// avformat_find_stream_info(ctx, NULL);
//// av_read_frame(ctx, &pkt);
//// etc..
You can waste your time rewriting FFMPEG from C++ to Delphi, or mess with wrapper libraries.
Or if you're just interested in playing a video in Delphi, then check out Mitov's VideoLab components.
http://www.mitov.com/products/videolab#components
If you want play Stream from memory you can make a virtual memory. I suggest BoxedAppSdk.
This will help you to make a virtual drive with virtual files that you can write on it and then give the virtual path to the player component that you have.
BoxedApp is not free but it is really awesome and very simple in use!

Resources