How to communicate with the reader using PC/SC - pcsc

I'm trying to communicate with an ACS ACR122U NFC card reader using the PC/SC API on Windows (winscard.dll).
According to this document, there is a pseudo-APDU available to read the card reader firmware version: FF 00 48 00 00
With a card in the reader, I have this working: I call SCardEstablishContext(), then SCardConnectA() to get a handle, then with the handle I call SCardTransmit(). I get an answer, just as expected.
But how to do that without a card in the reader?
The above document says:
• Pseudo-APDUs can be sent through the “ACR122U PICC Interface” if the tag is already connected
• Pseudo-APDUs can be sent using “Escape Command” if the tag is not yet presented
I have no idea what that means. If I try the same method as above without a card in the reader, the SCardConnectA() call fails with an SCARD_W_REMOVED_CARD error, which means I have no handle to call SCardTransmit() with.

Ok, I figured it out. To be allowed to call SCardConnectA() without a card in the reader, dwShareMode must be SCARD_SHARE_DIRECT and dwPreferredProtocols must be 0.

Related

Video call through the body of tegram api

I would like to know whether it is possible to start a video call with another user by means of the tdlib library and transfer a picture from a camera connected to a Raspberry Pi to this call? And if so, how do you do that? What methods should I use?
To work with video calls part of Telegram you need to use Telegram's WebRTC client (https://github.com/TelegramMessenger/tgcalls). With MTProto methods you can get params to start this library. Video and audio bytes passing via this library.
There is already implemented high level library for Python that works with official tgcalls library. But working with private calls in a TODO list. You can use this project as an example how to work with tgcalls library.
https://github.com/MarshalX/tgcalls
Here are the python sources With working code of video translator with youtube/m3ui/mp4
https://github.com/EverythingSuckz/tgvc-video-tests

Pass values from two Barcode Scanners to two specific texboxes.

I have two textboxes in a windowsform textbox1 and textbox2, I am trying to use two barcode scanners to send the values to each textbox.
If i Scan anything from Barcode Scanner 1 it should send value to textbox 1 without clicking on it!.
If i Scan anything from Barcode Scanner 2 it should send value to textbox 2 without clicking on it!.
Is there a way to do this?
Barcode scanners that are USB utilize HID or Human Interface Device. Typically, these are devices that humans use to directly control the operation of computer systems.
Microsoft offers a complete break down in this technology, I wish I could up load the PDF. I hate posting url's, as they can become stale; https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/introduction-to-hid-concepts
There are a few API's you can research and can be found above, I would investigate these:
Device Discovery and Setup
The following list identifies the HID API that an application can use to: identify the properties of a HID device, and to establish communication with that device. In addition, an application can use some of these API to identify a Top Level Collection.
HidD_GetAttributes
HidD_GetHidGuid
HidD_GetIndexedString
HidD_GetManufacturerString
HidD_GetPhysicalDescriptor
HidD_GetPreparsedData
HidD_GetProductString
HidD_GetSerialNumberString
HidD_GetNumInputBuffers
HidD_SetNumInputBuffers
Data Movement
The following list identifies the HID API that an application can use to move data back and forth between the app and a selected device.
HidD_GetInputReport
HidD_SetFeature
HidD_SetOutputReport
ReadFile
WriteFile
Another approach would be to see if the barcode scanner could emulate a serial port. This would denote which scanner is which, via the comm port.
For such use, there is POS for.NET or OPOS.
Both are part of UnifiedPOS.
Document -- retail/17-07-32 (UnifiedPOS Retail Peripheral Architecture, Version 1.14.1)
There is information and download here.
POS for .NET v1.14.1 SDK Documentation
Download Microsoft Point of Service for .NET v1.14.1 (POS for.NET)
OPOS
CCO Current Version
Since the program that actually controls the scanner is provided by the scanner vendor, you will obtain it.
Using them you need to create control objects for each individual scanner.
Which object is responsible for which scanner is specified by the DeviceName parameter of the Open method. The DeviceName is associated with USB VID/PID or connected COM port by configuration file or registry data.
Barcodes can be read from the scanner by processing Open, Claim, DeviceEnabled=true, DataEventEnabled=true on that object.
The object is notified by the DataEvent that the barcode has been read.
An application can register a separate event handler for each object, or by registering the same event handler and determining the sender parameter of the event notification, it is possible to identify from which scanner the barcode was read .
An application can read barcode data from the properties of the corresponding object and write it in the corresponding TextBox.

Can I use a USB pen drive with libusbdotnet

I have just started on libusbdotnet. I have downloaded the sample code from http://libusbdotnet.sourceforge.net/V2/Index.html.
I am using a JetFlash 4GB Flash drive (a libusb-win32 filter driver was added for this drive).
The ShowInfo code works perfectly, and I can see my device info with two endpoints. Following is the device info from pastebin
http://pastebin.com/2Jdph6bY
However, the ReadOnly sample code does not work.
http://pastebin.com/hNZaEt8N
My code is almost same as that from the libsubdotnet website. I have only changed the endpoint that UsbEndpointReader uses. I have changed it from Ep01 to Ep02, because I read that the first endpoint is a control endpoint used for configuration, access control and similar stuff.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
I always get the message "No more bytes!".
I thought that this is because of the absence of data, so I used the ReadWrite sample code.
http://pastebin.com/NiN5w9Jt
But here I also get "No more bytes!" message.
Interestly, the line
ec = writer.Write(Encoding.Default.GetBytes(cmdLine), 2000, out bytesWritten);
executes without errors.
Can pen drives be used for read write operations? Or is something wrong with the code?
A USB thumb drive implements the USB mass storage device class, which is a subset of SCSI. The specification is here.
You're not going to get anything sensible by just reading from an endpoint - you have to send the appropriate commands to get any response.
You have not chosen an easy device class to begin your exploration of USB - you may be better starting with something easier - a HID class device, perhaps (Mouse/Keyboard) though Windows does have enhanced security around mice and keyboards which may prevent you installing a filter.
If you meddle with the filesystem on the USB stick while it's mounted as a drive by Windows, you'll almost certainly run into cache-consistency problems, unless you're extremely careful about what kind of access you allow Windows to do.

Line break problems sending SMS through SMTP ftrom VB.NET

I wrote a VB.NET application to send notifications by SMS using an SMTP gateway (mobilenumber#mobileprovider.com).
The message includes line breaks and display well under most providers but not all.
For some providers, the message will display in one line with line breaks showing as "0D0A" which just won't work for me.
Is therea solution to this problem?
Using an SMS agregator is out of the question for my solution.
Yes, I did that. Turned out to be carrier specific.
Yet another problem i am having is specific to the phone model (one specific user receive the messages well on his old razor, changed to a new motorola phone with the same carrier and now receives an empty message).
Any ideas ?
This is neither vb.net or smtp problem.
It sure looks like it is mobile provider specific. Try checking your (mail message) encoding - have you tried pure ASCII?
If I'm not mistaken 0D0A is UTF-8 for line break...

Roll My Own Windows Joystick HID Driver?

I have a USB Joystick, and I want to write my own HID driver for it. Notably I want to inject delay between when the joystick input is received by Windows and when my application is notified of that input event. I would also like to change the identity of the joystick percieved by my application. I have never written a driver, let alone an HID driver, for Windows. Can anyone provide me with advice or pointers on how to go about doing this?
When you press knobs on the Joystick the electric signals reach the operating system (and onto the game) in the form of IRP's through the drivers chain. Intercepting these IRP's at some point and delaying the forwarding to the next driver can delay the joystick input. This can be achieved with driver filters.
To write windows drivers you need to use WinDDK.
The entrypoint of a windows driver is the DriverEntry function. In this function you will be hooking what IRP's you want to intercept and the callback functions that deal with them, in our case, the callback functions that delay the forwarding.
For example, say our IRP to be delayed is IRP_MJ_READ and our callback function is called CallbackDelayForwarding:
// the function that delays the IRP
NTSTATUS CallbackDelayForwarding(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
){
// delay the forwarding
}
// this is the driver entrypoint, similar to "main" in user-mode executables
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT pDriverObject,
IN PUNICODE_STRING RegistryPath
){
pDriverObject->MajorFunction[IRP_MJ_READ] = CallbackDelayForwarding;
...
}
To delay the forwarding inside CallbackDelayForwarding, you must use functions from the KeInitializeTimer family to simulate some sort of sleep (maybe in conjunction with locks), KeDelayExecutionThread etc.
To install your filter driver in the joystick driver chain, you can use .inf files.
Check the toaster filter driver sample in the WinDDK, you can find it at INSTALL_DIR/src/general/toaster/ see also here.
Related links:
http://www.rootkit.com/newsread.php?newsid=187
http://www.techtalkz.com/microsoft-device-drivers/269654-toaster-filter-driver.html
What you are trying to do is a filter driver.
Filter drivers are optional drivers that add value to or modify the behavior of a device. A filter driver can service one or more devices.
source: http://msdn.microsoft.com/en-us/library/ff545890.aspx
I think the WDK contains samples You ould have to download the Windows Driver Kit from here: http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx
The WDK probably contains a sample code to create a filter.
There is also the following download on microsoft's site : http://support.microsoft.com/kb/176417
It is probably a little bit outdated since USB was not supported pre-NT5.0, but maybe it is still relevant.
You might want to use Autohotkey. This is a script language for windows which can remap every keys of mouse/keyboard/joysticks. If you capture the key through a script and insert a delay before sending the right key/macro to the active application, you might have a part of a solution to your problem.
I was under the impression you could use <dinput.h>
joySetCapture(wnd, JOYSTICKID1) or joySetCapture(wnd,JOYSTICKID2)
then Joystick events would fire WM_JOYMOVE events, though what the wParam and lParam for the message would be I have no idea.
Then when your program closes or you no longer want joyReleaseCapture(JOYSTICKID1) etc.
it could just be empty params which then tell you to use joyGetPos or joyGetPosEx functions
to find the data for yourself from the USB device.