word BY8001::getNumberOfTracksCurrentFolder(){ sendCommand(0x1F); word numberTracksCurrentFolder = getReply(8,2); return numberTracksCurrentFolder; }
int main( int a_iArgc, char **a_pszArgv ) { int rc = 1; // Create buffers for PIN prompts for formatting using sprintf char szSoNewPinPrompt[ strlen( TOKEN_SO_NEW_PIN_PROMPT ) + 16 ]; char szUserNewPinPrompt[ strlen( TOKEN_USER_NEW_PIN_PROMPT ) + 16 ]; char *pszReply = NULL; char *pszSoPin = NULL; char *pszNewSoPin = NULL; char *pszNewUserPin = NULL; CK_RV rv = CKR_OK; CK_SESSION_HANDLE hSession = 0; // Set up i18n initIntlSys( ); // Parse the command if ( parseCmd( a_iArgc, a_pszArgv ) == -1 ) goto out; // Open the PKCS#11 TPM Token rv = openToken( g_pszToken ); if ( rv != CKR_OK ) goto out; // Check if the token is already initialized if ( isTokenInitialized( ) ) { // Warn and ask the user before clearing if ( !g_bYes ) { pszReply = getReply( TOKEN_CLEAR_PROMPT, 1 ); if ( !pszReply || ( strlen( pszReply ) == 0 ) || ( strcasecmp( pszReply, TOKEN_CLEAR_NO ) == 0 ) ) { goto out; } } // Prompt for the current SO password pszSoPin = getPlainPasswd( TOKEN_SO_PIN_PROMPT, FALSE ); if ( !pszSoPin ) goto out; } else pszSoPin = strdup( TOKEN_SO_INIT_PIN ); // Clear the TPM token rv = initToken( pszSoPin ); if ( rv != CKR_OK ) goto out; // Open a session rv = openTokenSession( CKF_RW_SESSION, &hSession ); if ( rv != CKR_OK ) goto out; // Login to the token rv = loginToken( hSession, CKU_SO, TOKEN_SO_INIT_PIN ); if ( rv != CKR_OK ) goto out; sprintf( szSoNewPinPrompt, TOKEN_SO_NEW_PIN_PROMPT, getMinPinLen( ), getMaxPinLen( ) ); while ( TRUE ) { // Prompt for a new SO password pszNewSoPin = getPlainPasswd( szSoNewPinPrompt, TRUE ); if ( !pszNewSoPin ) goto out; // Set the new password rv = setPin( hSession, TOKEN_SO_INIT_PIN, pszNewSoPin ); if ( rv == CKR_OK ) break; if ( ( rv == CKR_PIN_INVALID ) || ( rv == CKR_PIN_LEN_RANGE ) ) logError( TOKEN_INVALID_PIN ); else goto out; shredPasswd( pszNewSoPin ); } // Open a new session closeTokenSession( hSession ); hSession = 0; rv = openTokenSession( CKF_RW_SESSION, &hSession ); if ( rv != CKR_OK ) goto out; // Login to the token rv = loginToken( hSession, CKU_USER, TOKEN_USER_INIT_PIN ); if ( rv != CKR_OK ) goto out; sprintf( szUserNewPinPrompt, TOKEN_USER_NEW_PIN_PROMPT, getMinPinLen( ), getMaxPinLen( ) ); while ( TRUE ) { // Prompt for a new User password pszNewUserPin = getPlainPasswd( szUserNewPinPrompt, TRUE ); if ( !pszNewUserPin ) goto out; // Set the new password rv = setPin( hSession, TOKEN_USER_INIT_PIN, pszNewUserPin ); if ( rv == CKR_OK ) break; if ( ( rv == CKR_PIN_INVALID ) || ( rv == CKR_PIN_LEN_RANGE ) ) logError( TOKEN_INVALID_PIN ); else goto out; shredPasswd( pszNewUserPin ); } rc = 0; out: free( pszReply ); shredPasswd( pszSoPin ); shredPasswd( pszNewSoPin ); shredPasswd( pszNewUserPin ); if ( hSession ) closeTokenSession( hSession ); closeToken( ); if ( rc == 0 ) logInfo( TOKEN_CMD_SUCCESS, a_pszArgv[ 0 ] ); else logInfo( TOKEN_CMD_FAILED, a_pszArgv[ 0 ] ); return rc; }
word BY8001::getElapsedTrackPlaybackTime(){ sendCommand(0x1C); word elapsedTrackPlaybackTime = getReply(8,2); return elapsedTrackPlaybackTime; }
word BY8001::getTotalTrackPlaybackTime(){ sendCommand(0x1D); word totalTrackPlaybackTime = getReply(8,2); return totalTrackPlaybackTime; }
// Send prefix, suffix, and newline. Verify FONA response matches reply parameter. boolean FonaSMS::sendCheckReply(const __FlashStringHelper *prefix, char *suffix, const __FlashStringHelper *reply, uint16_t timeout) { getReply(prefix, suffix, timeout); return (strcmp_P(replybuffer, (prog_char*)reply) == 0); }
word BY8001::getCurrentTrackUSB(){ sendCommand(0x1A); word currentTrackUSB = getReply(8,0); return currentTrackUSB; }
word BY8001::getNumberOfTracksUSB(){ sendCommand(0x16); word numberOfTracksUSB = getReply(8,0); return numberOfTracksUSB; }
boolean Adafruit_FONA_3G::hangUp(void) { getReply(F("ATH")); return (strstr_P(replybuffer, (prog_char *)F("VOICE CALL: END")) != 0); }
byte BY8001::getLoopPlaybackMode(){ sendCommand(0x13); byte loopPlaybackMode = getReply(8,0); return loopPlaybackMode; }
word BY8001::getNumberOfTracksTF(){ sendCommand(0x15); word numberOfTracksTF = getReply(8,0); return numberOfTracksTF; }
byte BY8001::getEqualizerProfile(){ sendCommand(0x12); word profile = getReply(8,0); return (byte)profile; }
byte BY8001::getVolumeSetting(){ sendCommand(0x11); byte volume = getReply(8,0); return volume; }
// User Query Commands: byte BY8001::getPlaybackStatus(){ sendCommand(0x10); byte currentStatus = getReply(8,0); return currentStatus; }
boolean Adafruit_FONA::sendCheckReply(const __FlashStringHelper *send, const __FlashStringHelper *reply, uint16_t timeout) { getReply(send, timeout); return (strcmp_P(replybuffer, (prog_char*)reply) == 0); }
byte BY8001::getCurrentPlaybackDevice(){ sendCommand(0x18); byte device = getReply(8,0); return device; }
// Send prefix, suffix, suffix2, and newline. Verify FONA response matches reply parameter. boolean Adafruit_FONA::sendCheckReply(const __FlashStringHelper *prefix, int32_t suffix1, int32_t suffix2, const __FlashStringHelper *reply, uint16_t timeout) { getReply(prefix, suffix1, suffix2, timeout); return (strcmp_P(replybuffer, (prog_char*)reply) == 0); }
word BY8001::getCurrentTrackTF(){ sendCommand(0x19); word currentTrackTF = getReply(8,0); return currentTrackTF; }
// Send prefix, suffix, and newline. Verify FONA response matches reply parameter. bool Adafruit_FONA::sendCheckReply(const char *prefix, char *suffix, const char *reply, uint16_t timeout) { getReply(prefix, suffix, timeout); return (strcmp(replybuffer, (prog_char*)reply) == 0); }
int main(int argc, char **argv) { int sock, chunkSock; int offset; sockaddr_x dag; socklen_t daglen; char sdag[1024]; char *p; const char *fin; const char *fout; char cmd[512]; char reply[512]; int status = 0; say ("\n%s (%s): started\n", TITLE, VERSION); if (argc != 3) die(-1, "usage: cftp <source file> <dest file>\n"); fin = argv[1]; fout = argv[2]; // lookup the xia service daglen = sizeof(dag); if (XgetDAGbyName(NAME, &dag, &daglen) < 0) die(-1, "unable to locate: %s\n", NAME); // create a socket, and listen for incoming connections if ((sock = Xsocket(AF_XIA, SOCK_STREAM, 0)) < 0) die(-1, "Unable to create the listening socket\n"); if (Xconnect(sock, (struct sockaddr*)&dag, daglen) < 0) { Xclose(sock); die(-1, "Unable to bind to the dag: %s\n", dag); } // save the AD and HID for later. This seems hacky // we need to find a better way to deal with this Graph g(&dag); strncpy(sdag, g.dag_string().c_str(), sizeof(sdag)); ad = strstr(sdag, "AD:"); p = strchr(ad, ' '); *p = 0; hid = p + 1; hid = strstr(hid, "HID:"); p = strchr(hid, ' '); *p = 0; // send the file request sprintf(cmd, "get %s", fin); sendCmd(sock, cmd); // get back number of chunks in the file getReply(sock, reply, sizeof(reply)); int count = atoi(&reply[4]); if ((chunkSock = Xsocket(AF_XIA, XSOCK_CHUNK, 0)) < 0) die(-1, "unable to create chunk socket\n"); FILE *f = fopen(fout, "w"); offset = 0; while (offset < count) { int num = NUM_CHUNKS; if (count - offset < num) num = count - offset; // tell the server we want a list of <num> cids starting at location <offset> sprintf(cmd, "block %d:%d", offset, num); sendCmd(sock, cmd); getReply(sock, reply, sizeof(reply)); offset += NUM_CHUNKS; if (getFileData(chunkSock, f, &reply[4]) < 0) { status= -1; break; } } fclose(f); if (status < 0) { unlink(fin); } say("shutting down\n"); sendCmd(sock, "done"); Xclose(sock); Xclose(chunkSock); return status; }