static jbyteArray android_os_Parcel_marshall(JNIEnv* env, jclass clazz, jlong nativePtr) { Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); if (parcel == NULL) { return NULL; } // do not marshall if there are binder objects in the parcel if (parcel->objectsCount()) { jniThrowException(env, "java/lang/RuntimeException", "Tried to marshall a Parcel that contained Binder objects."); return NULL; } jbyteArray ret = env->NewByteArray(parcel->dataSize()); if (ret != NULL) { jbyte* array = (jbyte*)env->GetPrimitiveArrayCritical(ret, 0); if (array != NULL) { memcpy(array, parcel->data(), parcel->dataSize()); env->ReleasePrimitiveArrayCritical(ret, array, 0); } } return ret; }
int PhoneMachine::incomingThread() { char boardname[PROPERTY_VALUE_MAX]; if (property_get("ro.product.board", boardname, "") > 0) { SLOGV("%s: -------------Board %s -----------------\n", __FUNCTION__, boardname); // QCOM Version 4.1.2 onwards, supports multiple clients and needs a SUB1/2 string to // identify client // For this example code we will just use "SUB1" for client 0 if ( !strcasecmp(boardname, "msm8960")) { char *sub = "SUB1"; int ret = ::send(mRILfd, sub, sizeof(sub), 0); if (ret != (int) sizeof(sub)) { perror("Socket write error when sending parcel"); return ret; } SLOGV("%s: sent SUB1\n", __FUNCTION__); } } else SLOGE("%s: could not get device name\n", __FUNCTION__); while (1) { uint32_t header; int ret = read(mRILfd, &header, sizeof(header)); if (ret != sizeof(header)) { SLOGW("Read %d bytes instead of %d\n", ret, sizeof(header)); perror("PhoneMachine::incomingThread read on header"); return ret; } int data_size = ntohl(header); Parcel data; ret = read(mRILfd, data.writeInplace(data_size), data_size); if (ret != data_size) { perror("PhoneMachine::incomingThread read on payload"); return ret; } if (mDebug & DEBUG_INCOMING) { SLOGV("<<<<<<< INCOMING <<<<<<<<<<\n"); const uint8_t *ptr = data.data(); for (int i = 0 ; i < data_size ; i++ ) { SLOGV("%02x ", *ptr++); if ((i+1) % 8 == 0 || (i+1 >= data_size)) SLOGV("\n"); } SLOGV("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); } data.setDataPosition(0); int type = data.readInt32(); // SLOGV("New message received: %d bytes type=%s\n", data_size, // (type ==RESPONSE_SOLICITED ? "solicited" : "unsolicited")); if (type == RESPONSE_SOLICITED) receiveSolicited(data); else receiveUnsolicited(data); } return NO_ERROR; }
NS_IMETHOD Run() { assertIsNfcServiceThread(); Parcel parcel; parcel.writeInt32(0); // Parcel Size. mHandler->Marshall(parcel, mOptions); parcel.setDataPosition(0); uint32_t sizeBE = htonl(parcel.dataSize() - sizeof(int)); parcel.writeInt32(sizeBE); mConsumer->PostToNfcDaemon(parcel.data(), parcel.dataSize()); return NS_OK; }
/* * packRILcommandString * Used for packing standard AT command string to RIL command. * * IN *inStr : AT command string with NULL terminate * IN *prefix : prefix of AT response * OUT **outCmd : RAW RIL command out. Caller is responsible to free this resource. * RETUURN : Length of outCmd data. */ size_t packRILCommand(char *inStr, char *prefix, char **outCmd) { /* |Request Enum |Request Token|Number of Strings|Srings.....| * |<--4 bytes-->|<--4 bytes-->|<--- 4 bytes --->|<------ ->| */ size_t length = 0; char *cmdStr[2] = {NULL,NULL}; char *pData = NULL; Parcel p; static int s_token = 0; if ((NULL == inStr)||(NULL == outCmd)) { return 0; } cmdStr[0] = inStr; cmdStr[1] = prefix; // p.writeInt32(length); /* fake write to reserve space */ p.writeInt32(RIL_REQUEST_OEM_HOOK_STRINGS); p.writeInt32(s_token++); packStrings(p,cmdStr,2*sizeof(char *)); /* ONLY support 1 string now */ length = p.dataSize(); #if 0 offset = p.dataPosition(); /* Store data position */ p.setDataPosition(0); /* Move to the buffer pointer to head */ p.writeInt32(length - 4); /* Update data length */ p.setDataPosition(offset); /* Restore data position */ #endif /* 0 */ pData = (char *) malloc(length); if (NULL != pData) { memcpy(pData,p.data(),length); *outCmd = pData; LOGI("packRILCommand: %d bytes\n",length); printRawData((const void *) pData, length); } else { return 0; } return length; }