How to download and install NFC sample applet on Fudan FM1280 dual interface card? - applet

I have a dual interface Fudan FM1280 which supports both contact (ISO7816) and contactless (ISO14443) interfaces connected to the same chip card. All I want to do is to install an HCI applet on this card.
To do so, I have used the example code from Simalliance (Mobile Near Field Communication (Mobile NFC) Stepping Stones) named "a Reader Mode Applet based on ToolKit interaction". The source code for that example is as below:
package pkgReaderModeApplet;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.MultiSelectable;
import uicc.toolkit.ToolkitConstants;
import uicc.toolkit.ToolkitException;
import uicc.toolkit.ToolkitInterface;
import uicc.toolkit.ToolkitRegistry;
import uicc.hci.framework.HCIDevice;
import uicc.hci.framework.HCIMessage;
import uicc.hci.framework.HCIService;
import uicc.hci.services.connectivity.ConnectivityService;
import uicc.hci.services.readermode.ReaderListener;
import uicc.hci.services.readermode.ReaderMessage;
import uicc.hci.services.readermode.ReaderService;
public class ReaderModeApplet extends Applet implements ReaderListener, MultiSelectable, ToolkitConstants, ToolkitInterface {
private ToolkitRegistry myToolKitReg;
private HCIService myReaderService;
private ConnectivityService myConnectivityService;
private ReaderModeApplet() {
myReaderService = (ReaderService) HCIDevice.getHCIService(HCIDevice.READER_SERVICE_ID);
myReaderService.register(this);
}
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new ReaderModeApplet().register();
}
public void processToolkit(short event) throws ToolkitException {
switch(event) {
case EVENT_MENU_SELECTION:
myReaderService.activateEvent(ReaderListener.EVENT_TARGET_DISCOVERED);
break;
case EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY:
myToolKitReg.clearEvent(EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY);
break;
}
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
public void onCallback(byte event, HCIMessage myHCIMessage) {
// First: Reception of Datas
short offset = myHCIMessage.getReceiveOffset();
short length = myHCIMessage.getReceiveLength();
byte[] IncomingBuffer = myHCIMessage.getReceiveBuffer();
switch(event){
//Target Discovered !!!
case ReaderListener.EVENT_TARGET_DISCOVERED:
//Activation of relevant events
myReaderService.activateEvent(ReaderListener.EVENT_WRITE_EXCHANGE_DATA_RESPONSE);
myReaderService.activateEvent(ReaderListener.EVENT_GET_PARAMETER_RESPONSE);
// Check if status is OK
if (IncomingBuffer[(short)(offset) ] == ReaderMessage.SINGLE_TARGET_STATUS) {
// Copy your Datas into IncomingBuffer
// and send the first message
// prepareAndSendWriteXchgDataCommand(byte timeout, byte[] data, short offset, short len)
((ReaderMessage)myHCIMessage).prepareAndSendWriteXchgDataCommand((byte) -1, IncomingBuffer, (short)offset, (short)length);
// Or retrieves informations on the Target discovered
((ReaderService)myReaderService).getReaderRFType();
((ReaderMessage)myHCIMessage).prepareAndSendGetParameterCommand(ReaderMessage.
PARAM_ID_TYPE_B_READER_AFI);
} else {
// If status is equal to MULTIPLE_TARGET_STATUS
((ReaderMessage)myHCIMessage).restartReaderModeProcedure();
// Warn the user
}
break;
//Response received !!
case ReaderListener.EVENT_WRITE_EXCHANGE_DATA_RESPONSE:
//First check if response is a Success
if(myHCIMessage.getInstruction() == (byte)(HCIMessage.RESP_ANY_OK)) {
//Copy your Datas into IncomingBuffer
// and send your next message
((ReaderMessage)myHCIMessage).prepareAndSendWriteXchgDataCommand((byte) -1, IncomingBuffer, (short)offset, (short)length);
// Or you have all the datas and you want to process them
myToolKitReg.setEvent(ToolkitConstants.EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY);
myConnectivityService = (ConnectivityService)HCIDevice.getHCIService(HCIDevice.CONNECTIVITY_SERVICE_ID);
myConnectivityService.prepareAndSendConnectivityEvent();
myReaderService.deactivateEvent(ReaderListener.EVENT_TARGET_DISCOVERED);
} else {
//Or restart the procedure
((ReaderMessage)myHCIMessage).restartReaderModeProcedure();
}
break;
case ReaderListener.EVENT_GET_PARAMETER_RESPONSE:
default:
break;
}
}
public void deselect(boolean arg0) {
// TODO Auto-generated method stub
}
public boolean select(boolean arg0) {
// TODO Auto-generated method stub
return true;
}
}
I am using Java card 2.2.2, hci-api-for-java-card-REL-920 and uicc-api-for-java-card-REL-13_0 to compile this code (using Eclipse) and it results in the cap file needed to be downloaded on card.
I am using pyApduTool to interface card. As I connect to card and try to download this applet on my card, I get an error as below and never get to installing step for the downloaded file.
This card originally contains few packages as:
And no applet installed. Now, what is the problem with applet downloading on card?

Related

How to save a phone number in an incoming call in Flutter

I want to get the incoming caller's phone number in my flutter app.
I'm trying the solution in this answer, but it doesn't work.
I have no knowledge about it at all and have not been able to find a resource with all the stages. What am I doing wrong?
The full code: https://github.com/gulsenkeskin/phone_call_demo
I solved the problem. If anyone needs it, he can look at this link
You can't do this in Flutter. To receive incoming call you should go for native, in the number String you will receive the incoming caller's number.
package com.anand.example;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public class CallReceiver extends BroadcastReceiver {
String number = "";
#Override
public void onReceive(Context context, Intent intent) {
number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (number != null) {
if (number != null) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
System.out.println(number);
// call attended
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// call ended
System.out.println(number);
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
System.out.println(number);
// incoming call
}
}
}
}
}

Getting user data in NewProjectCreationPage in Eclipse Plugin

I have been successful in making a plugin. However now i need that on project creation page i add some more textboxes to get the user information. Also i need to use this information to add into the auto generated .php files made in project directory.
I want to know how can i override the WizardNewProjectCreationPage to add some more textboxes to the already given layout. I am pretty new to plugin development. Here is the code for my custom wizard.
import java.net.URI;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import rudraxplugin.pages.MyPageOne;
import rudraxplugin.projects.RudraxSupport;
public class CustomProjectNewWizard extends Wizard implements INewWizard, IExecutableExtension {
private WizardNewProjectCreationPage _pageOne;
protected MyPageOne one;
private IConfigurationElement _configurationElement;
public CustomProjectNewWizard() {
// TODO Auto-generated constructor stub
setWindowTitle("RudraX");
}
#Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
// TODO Auto-generated method stub
}
#Override
public void addPages() {
super.addPages();
_pageOne = new WizardNewProjectCreationPage("From Scratch Project Wizard");
_pageOne.setTitle("From Scratch Project");
_pageOne.setDescription("Create something from scratch.");
addPage(one);
addPage(_pageOne);
}
#Override
public boolean performFinish() {
String name = _pageOne.getProjectName();
URI location = null;
if (!_pageOne.useDefaults()) {
location = _pageOne.getLocationURI();
System.err.println("location: " + location.toString()); //$NON-NLS-1$
} // else location == null
RudraxSupport.createProject(name, location);
// Add this
BasicNewProjectResourceWizard.updatePerspective(_configurationElement);
return true;
}
#Override
public void setInitializationData(IConfigurationElement config,
String propertyName, Object data) throws CoreException {
_configurationElement = config;
// TODO Auto-generated method stub
}
}
Ask for any other code required. Any help is appreciated. Thank You.
Instead of using WizardNewProjectCreationPage directly create a new class extending WizardNewProjectCreationPage and override the createControl method to create new controls:
class MyNewProjectCreationPage extends WizardNewProjectCreationPage
{
#Override
public void createControl(Composite parent)
{
super.createControl(parent);
Composite body = (Composite)getControl();
... create new controls here
}
}

Convert to .cap error- invalid AID 1.0 in Eclipse

This is the source code that I want to upload to my card :
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
public class ReadMemo extends Applet {
private ReadMemo() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new ReadMemo().register();
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
}
As you see, the program do nothing! but why when I want to convert it to .cap file, I receive this error :
invalid AID 1.0
Note :
my package ID : 0x00:0x01:0x02:0x03:0x04:0x05:0x06:0x07
my applet ID : 0x00:0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08
Move your code out of the default package (never use the default package in Java). Because the package_name argument is empty, the arguments have been shifted to the left, and it will now see the version number as an AID. Hence the strange error.

Reading xls file in gwt

I am looking to read xls file using the gwt RPC and when I am using the code which excecuted fine in normal file it is unable to load the file and giving me null pointer exception.
Following is the code
{
{
import com.arosys.readExcel.ReadXLSX;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.Preview.client.GWTReadXL;
import java.io.InputStream;
import com.arosys.customexception.FileNotFoundException;
import com.arosys.logger.LoggerFactory;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* #author Amandeep
*/
public class GWTReadXLImpl extends RemoteServiceServlet implements GWTReadXL
{
private String fileName;
private String[] Header=null;
private String[] RowData=null;
private int sheetindex;
private String sheetname;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
private static Logger logger=null;
public void loadXlsxFile() throws Exception
{
logger.info("inside loadxlsxfile:::"+fileName);
InputStream resourceAsStream =ClassLoader.getSystemClassLoader().getSystemResourceAsStream("c:\\test2.xlsx");
logger.info("resourceAsStream-"+resourceAsStream);
if(resourceAsStream==null)
throw new FileNotFoundException("unable to locate give file");
else
{
try
{
workbook = new XSSFWorkbook(resourceAsStream);
sheet = workbook.getSheetAt(sheetindex);
}
catch (Exception ex)
{
logger.error(ex.getMessage());
}
}
}// end loadxlsxFile
public String getNumberOfColumns() throws Exception
{
int NO_OF_Column=0; XSSFCell cell = null;
loadXlsxFile();
Iterator rowIter = sheet.rowIterator();
XSSFRow firstRow = (XSSFRow) rowIter.next();
Iterator cellIter = firstRow.cellIterator();
while(cellIter.hasNext())
{
cell = (XSSFCell) cellIter.next();
NO_OF_Column++;
}
return NO_OF_Column+"";
}
}
}
I am calling it in client program by this code:
final AsyncCallback<String> callback1 = new AsyncCallback<String>() {
public void onSuccess(String result) {
RootPanel.get().add(new Label("In success"));
if(result==null)
{
RootPanel.get().add(new Label("result is null"));
}
RootPanel.get().add(new Label("result is"+result));
}
public void onFailure(Throwable caught) {
RootPanel.get().add(new Label("In Failure"+caught));
}
};
try{
getService().getNumberOfColumns(callback1);
}catch(Exception e){}
}
Pls tell me how can I resolve this issue as the code runs fine when run through the normal java file.
Why are using using the system classloader, rather than the normal one?
But, If you still want to use then look at this..
As you are using like a web application. In that case, you need to use the ClassLoader which is obtained as follows:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
This one has access to the all classpath paths tied to the webapplication in question and you're not anymore dependent on which parent classloader (a webapp has more than one!) has loaded your class.
Then, on this classloader, you need to just call getResourceAsStream() to get a classpath resource as stream, not the getSystemResourceAsStream() which is dependent on how the webapplication is started. You don't want to be dependent on that as well since you have no control over it at external hosting:
InputStream input = classLoader.getResourceAsStream("filename.extension");
The location of file should in your CLASSPATH.

Control Netbeans from Commandline: attach Debugger from Shell-script

I'm using a daemon-script which is monitoring a remote server. When the remote server is up, i want that Netbeans automatically connects it's Debugger to the remote Server.
Is it possible to control this behavior from commandline?
To type Something like
netbeans --attach-debugger 192.168.178.34:9009
inside a terminal to do that? Or what other ways do i have to get access to Netbeans-internal stuff? (until now, i was just a "user" of Netbeans so i don't know the internals and how to access them very well)
Or will i have to write a Netbeans Plugin to do that? If yes, can you give me a good starting point to add that functionality?
Ok since there is no option to attach the Debugger from commandline, i wrote a Netbeans Plugin with the help of this blog entry and this thread from the NB-mailinglist. Now i'm able to call my plugin actions from the Commandline.
So build a simple NetBeans Module, which contains 2 important classes.
This is the class which gets the commandline parameters and forwards them to my Action:
import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.Action;
import org.netbeans.api.sendopts.CommandException;
import org.netbeans.spi.sendopts.Env;
import org.netbeans.spi.sendopts.OptionProcessor;
import org.netbeans.spi.sendopts.Option;
import org.openide.ErrorManager;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.WindowManager;
#ServiceProvider(service = OptionProcessor.class)
public class TriggerActionCommandLine extends OptionProcessor {
//Here we specify "runAction" as the new key in the command,
//but it could be any other string you like, of course:
private static Option action = Option.requiredArgument(Option.NO_SHORT_NAME, "debug");
private static final Logger logger = Logger.getLogger(AttachDebugger.class.getName());
#Override
public Set<org.netbeans.spi.sendopts.Option> getOptions() {
return Collections.singleton(action);
}
#Override
protected void process(Env env, Map<Option, String[]> values) throws CommandException {
final String[] args = (String[]) values.get(action);
if (args.length > 0) {
//Set the value to be the first argument from the command line,
//i.e., this is "GreetAction", for example:
final String ip = args[0];
//Wait until the UI is constructed,
//otherwise you will fail to retrieve your action:
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
#Override
public void run() {
//Then find & perform the action:
Action a = findAction(AttachDebugger.ACTION_NAME);
// forward IP address to Action
ActionEvent e = new ActionEvent(this, 1, ip);
a.actionPerformed(e);
}
});
}
}
public Action findAction(String actionName) {
FileObject myActionsFolder = FileUtil.getConfigFile("Actions/PSFActions");
FileObject[] myActionsFolderKids = myActionsFolder.getChildren();
for (FileObject fileObject : myActionsFolderKids) {
logger.info(fileObject.getName());
//Probably want to make this more robust,
//but the point is that here we find a particular Action:
if (fileObject.getName().contains(actionName)) {
try {
DataObject dob = DataObject.find(fileObject);
InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class);
if (ic != null) {
Object instance = ic.instanceCreate();
if (instance instanceof Action) {
Action a = (Action) instance;
return a;
}
}
} catch (Exception e) {
ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
return null;
}
}
}
return null;
}
}
This is my Plugin Action which attaches the Debugger to the given remote address:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.debugger.jpda.DebuggerStartException;
import org.netbeans.api.debugger.jpda.JPDADebugger;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.python.util.PythonInterpreter;
#ActionID(category = "PSFActions", id = "de.mackaz.AttachDebugger")
#ActionRegistration(displayName = "#CTL_AttachDebuggerAction")
#ActionReferences({
#ActionReference(path = "Menu/Tools", position = 1800, separatorBefore = 1750, separatorAfter = 1850)
})
public final class AttachDebugger implements ActionListener {
private static final Logger logger = Logger.getLogger(AttachDebugger.class.getName());
public static final String ACTION_NAME="AttachDebugger";
#Override
public void actionPerformed(ActionEvent e) {
String ip;
if (!e.getActionCommand().contains("Attach Debugger")) {
ip = e.getActionCommand();
} else {
ip = lookupIP();
}
try {
logger.log(Level.INFO, "Attaching Debugger to IP {0}", ip);
JPDADebugger.attach(
ip,
9009,
new Object[]{null});
} catch (DebuggerStartException ex) {
int msgType = NotifyDescriptor.ERROR_MESSAGE;
String msg = "Failed to connect debugger to remote IP " + ip;
NotifyDescriptor errorDescriptor = new NotifyDescriptor.Message(msg, msgType);
DialogDisplayer.getDefault().notify(errorDescriptor);
}
}
}
Now i can attach the Netbeans debugger to a specific address by calling netbeans/bin/netbeans --debug 192.168.178.79