summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/com/android/nfc/NfcService.java21
-rwxr-xr-xsrc/com/android/nfc/mytag/MyTagClient.java11
-rwxr-xr-xsrc/com/android/nfc/mytag/MyTagServer.java15
3 files changed, 40 insertions, 7 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index db8afa6..826fd76 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -254,6 +254,8 @@ public class NfcService extends Application {
Log.d(TAG, "Disabling NFC. previous=" + previouslyEnabled);
if (previouslyEnabled) {
+ /* tear down the my tag server */
+ mMyTagServer.stop();
isSuccess = mManager.deinitialize();
Log.d(TAG, "NFC success of deinitialize = " + isSuccess);
if (isSuccess) {
@@ -445,6 +447,7 @@ public class NfcService extends Application {
int sockeHandle = mGeneratedSocketHandle;
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
+ Log.d(TAG, "creating llcp socket while activated");
NativeLlcpSocket socket;
socket = mManager.doCreateLlcpSocket(sap, miu, rw, linearBufferLength);
@@ -466,6 +469,8 @@ public class NfcService extends Application {
/* Get Error Status */
int errorStatus = mManager.doGetLastError();
+ Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(errorStatus));
+
switch (errorStatus) {
case ErrorCodes.ERROR_BUFFER_TO_SMALL:
return ErrorCodes.ERROR_BUFFER_TO_SMALL;
@@ -476,6 +481,7 @@ public class NfcService extends Application {
}
}
} else {
+ Log.d(TAG, "registering llcp socket while not activated");
/* Check SAP is not already used */
if (!CheckSocketSap(sap)) {
@@ -1745,6 +1751,9 @@ public class NfcService extends Application {
/* Start polling loop */
maybeEnableDiscovery();
+ /* bring up the my tag server */
+ //mMyTagServer.start();
+
} else {
mIsNfcEnabled = false;
}
@@ -1758,7 +1767,6 @@ public class NfcService extends Application {
private synchronized void maybeEnableDiscovery() {
if (mScreenOn && mIsNfcEnabled) {
mManager.enableDiscovery(DISCOVERY_MODE_READER);
-// mMyTagServer.start();
}
}
@@ -1766,7 +1774,6 @@ public class NfcService extends Application {
private synchronized void maybeDisableDiscovery() {
if (mIsNfcEnabled) {
mManager.disableDiscovery();
-// mMyTagServer.stop();
}
}
@@ -2007,11 +2014,13 @@ public class NfcService extends Application {
registeredSocket.mlinearBufferLength);
if (serviceSocket != null) {
+ Log.d(TAG, "service socket created");
/* Add the socket into the socket map */
synchronized(NfcService.this) {
mSocketMap.put(registeredSocket.mHandle, serviceSocket);
}
} else {
+ Log.d(TAG, "FAILED to create service socket");
/* socket creation error - update the socket
* handle counter */
mGeneratedSocketHandle -= 1;
@@ -2025,11 +2034,13 @@ public class NfcService extends Application {
registeredSocket.mMiu, registeredSocket.mRw,
registeredSocket.mlinearBufferLength);
if (clientSocket != null) {
+ Log.d(TAG, "socket created");
/* Add the socket into the socket map */
synchronized(NfcService.this) {
mSocketMap.put(registeredSocket.mHandle, clientSocket);
}
} else {
+ Log.d(TAG, "FAILED to create service socket");
/* socket creation error - update the socket
* handle counter */
mGeneratedSocketHandle -= 1;
@@ -2042,11 +2053,13 @@ public class NfcService extends Application {
connectionlessSocket = mManager.doCreateLlcpConnectionlessSocket(
registeredSocket.mSap);
if (connectionlessSocket != null) {
+ Log.d(TAG, "connectionless socket created");
/* Add the socket into the socket map */
synchronized(NfcService.this) {
mSocketMap.put(registeredSocket.mHandle, connectionlessSocket);
}
} else {
+ Log.d(TAG, "FAILED to create service socket");
/* socket creation error - update the socket
* handle counter */
mGeneratedSocketHandle -= 1;
@@ -2173,6 +2186,7 @@ public class NfcService extends Application {
Log.d(TAG, "LLCP Activation message");
if (device.getMode() == NativeP2pDevice.MODE_P2P_TARGET) {
+ Log.d(TAG, "NativeP2pDevice.MODE_P2P_TARGET");
if (device.doConnect()) {
/* Check Llcp compliancy */
if (mManager.doCheckLlcp()) {
@@ -2196,6 +2210,7 @@ public class NfcService extends Application {
}
} else if (device.getMode() == NativeP2pDevice.MODE_P2P_INITIATOR) {
+ Log.d(TAG, "NativeP2pDevice.MODE_P2P_INITIATOR");
/* Check Llcp compliancy */
if (mManager.doCheckLlcp()) {
/* Activate Llcp Link */
@@ -2203,6 +2218,8 @@ public class NfcService extends Application {
Log.d(TAG, "Target Activate LLCP OK");
activateLlcpLink();
}
+ } else {
+ Log.d(TAG, "checkLlcp failed");
}
}
break;
diff --git a/src/com/android/nfc/mytag/MyTagClient.java b/src/com/android/nfc/mytag/MyTagClient.java
index 047db63..241d9e2 100755
--- a/src/com/android/nfc/mytag/MyTagClient.java
+++ b/src/com/android/nfc/mytag/MyTagClient.java
@@ -37,6 +37,7 @@ import java.io.IOException;
*/
public class MyTagClient extends BroadcastReceiver {
private static final String TAG = "MyTagClient";
+ private static final boolean DBG = true;
public MyTagClient(Context context) {
context.registerReceiver(this, new IntentFilter(NfcAdapter.ACTION_LLCP_LINK_STATE_CHANGED));
@@ -44,10 +45,12 @@ public class MyTagClient extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
+ if (DBG) Log.d(TAG, "LLCP connection up and running");
NfcAdapter adapter = NfcAdapter.getDefaultAdapter();
NdefMessage msg = adapter.getLocalNdefMessage();
if (msg == null) {
+ if (DBG) Log.d(TAG, "No MyTag set, exiting");
// Nothing to send to the server
return;
}
@@ -56,6 +59,7 @@ public class MyTagClient extends BroadcastReceiver {
NfcAdapter.LLCP_LINK_STATE_DEACTIVATED);
if (linkState != NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
+ if (DBG) Log.d(TAG, "LLCP connection not activated, exiting");
return;
}
@@ -68,12 +72,17 @@ public class MyTagClient extends BroadcastReceiver {
NfcService service = NfcService.getInstance();
NdefMessage msg = msgs[0];
try {
+ if (DBG) Log.d(TAG, "about to create socket");
// Connect to the my tag server on the remote side
LlcpSocket sock = service.createLlcpSocket(0, 128, 1, 1024);
- sock.connect(MyTagServer.SERVICE_NAME);
+ if (DBG) Log.d(TAG, "about to connect");
+// sock.connect(MyTagServer.SERVICE_NAME);
+ sock.connect(0x20);
// Push the local NDEF message to the server
+ if (DBG) Log.d(TAG, "about to send");
sock.send(msg.toByteArray());
+ if (DBG) Log.d(TAG, "about to close");
sock.close();
} catch (IOException e) {
diff --git a/src/com/android/nfc/mytag/MyTagServer.java b/src/com/android/nfc/mytag/MyTagServer.java
index 9cbb91a..f3110f8 100755
--- a/src/com/android/nfc/mytag/MyTagServer.java
+++ b/src/com/android/nfc/mytag/MyTagServer.java
@@ -36,13 +36,13 @@ import java.io.IOException;
public class MyTagServer {
private static final String TAG = "~~~~~~~~~~~~~~~";
private static final boolean DBG = true;
+ private static final int SERVICE_SAP = 0x20;
static final String SERVICE_NAME = "com.android.mytag";
- static final int SERVICE_SAP = 0x20;
NfcService mService = NfcService.getInstance();
/** Protected by 'this', null when stopped, non-null when running */
- ServerThread mServerThread;
+ ServerThread mServerThread = null;
/** Connection class, used to handle incoming connections */
private class ConnectionThread extends Thread {
@@ -65,15 +65,18 @@ public class MyTagServer {
while(!connectionBroken) {
try {
size = mSock.receive(partial);
+ if (DBG) Log.d(TAG, "read " + size + " bytes");
buffer.write(partial, 0, size);
} catch (IOException e) {
// Connection broken
connectionBroken = true;
+ if (DBG) Log.d(TAG, "connection broken");
}
}
// Build NDEF message from the stream
NdefMessage msg = new NdefMessage(buffer.toByteArray());
+ if (DBG) Log.d(TAG, "got message " + msg.toString());
// Send the intent for the fake tag
mService.sendMockNdefTag(msg);
@@ -90,14 +93,18 @@ public class MyTagServer {
@Override
public void run() {
- while(mRunning) {
- mServerSocket = mService.createLlcpServiceSocket(SERVICE_SAP, SERVICE_NAME,
+ while (mRunning) {
+ if (DBG) Log.d(TAG, "about create LLCP service socket");
+ mServerSocket = mService.createLlcpServiceSocket(SERVICE_SAP, null,
128, 1, 1024);
if (mServerSocket == null) {
+ Log.d(TAG, "failed to create LLCP service socket");
continue;
}
+ if (DBG) Log.d(TAG, "created LLCP service socket");
try {
if (mRunning) {
+ if (DBG) Log.d(TAG, "about to accept");
LlcpSocket communicationSocket = mServerSocket.accept();
if (DBG) Log.d(TAG, "accept returned " + communicationSocket);
if (communicationSocket != null) {