void solicitar_recurso(t_solicitud* solicitud,ITEM_NIVEL* listaItems,int*socket,t_list** personajes_deadlock){ ITEM_NIVEL* recurso = buscar_item(solicitud->id_recurso, listaItems); int* data = malloc(sizeof(int)); if((recurso->posx == solicitud->x) && (recurso->posy == solicitud->y)){ t_personaje_deadlock* pj_dl = getPersonajeDeadLock(*personajes_deadlock,solicitud->id_pj); int i = getIndexRecurso(solicitud->id_recurso,pj_dl->recursosAsignados); if (recurso->quantity > 0) { //todo meter las dos fx en una sola restarRecurso(listaItems, solicitud->id_recurso); pj_dl->recursosAsignados[i].cantidad++; data[0]=RECURSO_OTORGADO; sendBytes(socket,data,sizeof(int), logger); }else{ pj_dl->id_peticion = recurso->id; data[0]=NO_HAY_RECURSOS; sendBytes(socket,data,sizeof(int), logger); } }else{ //no estaba en la posicion indicada } }
/** * Method to send the bytes of a file to the client */ void getFile(int sock, char * filename) { printf("Looking for file %s\n", filename); FILE * fp = fopen(filename, "r"); if (fp == NULL) { // the file did not exist // close the socket perror("fopen"); closeSock(sock); return; } printf("Found the file %s, sending Found\n", filename); // Send bytes to say we found it sendBytes(sock, "Found", strlen("Found")); // Send the bytes of the file char buf[1024]; memset(buf, 0, 1024); ssize_t retVal = 1024; while (retVal == 1024) { retVal = fread(buf, 1, 1024, fp); sendBytes(sock, buf, strlen(buf)); } closeSock(sock); fclose(fp); }
void doOfflineListFiles(ClientThreadResource * res , ListenSocket clientSocket ,RuntimeErrorValidator * validator){ WIN32_FIND_DATA ffd; LARGE_INTEGER filesize; char szDir[MAX_PATH]; char * arrayFileSize; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD lastError = 0; char * thePath = concat(res->heapHandler , 3 , getDataDirectory() , res->relativeWorkingDir , "*"); hFind = FindFirstFileA(thePath, &ffd); while( hFind != INVALID_HANDLE_VALUE && FindNextFileA(hFind, &ffd) != 0){ int result; if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){ char * msg = concat(res->heapHandler, 3, "drwxrwxrwx 1 ftp ftp 4096 Jul 11 2011 ", ffd.cFileName , CHARACTER_CRLF); sendBytes(clientSocket , msg , strlen(msg)); /*sendMessage( clientSocket , concat(res->heapHandler, 3, "drwxrwxrwx 1 ftp ftp 4096 Jul 11 2011 ", ffd.cFileName , CHARACTER_CRLF) , &result);*/ } else { filesize.LowPart = ffd.nFileSizeLow; filesize.HighPart = ffd.nFileSizeHigh; arrayFileSize = intToString( ffd.nFileSizeLow , res->heapHandler ); { char * msg = concat(res->heapHandler, 5 , "-rwxrwxrwx 1 ftp ftp " , arrayFileSize , "Jul 11 2011 " , ffd.cFileName , CHARACTER_CRLF); sendBytes(clientSocket , msg , strlen(msg)); } /*sendMessage( clientSocket , concat(res->heapHandler, 5 , "-rwxrwxrwx 1 ftp ftp " , arrayFileSize , "Jul 11 2011 " , ffd.cFileName , CHARACTER_CRLF) , &result);*/ } } if ( INVALID_HANDLE_VALUE == hFind ) { error("Error al leer lista de archivos (FindFirstFile)"); } lastError = GetLastError(); FindClose(hFind); if (lastError == 0 || lastError == ERROR_NO_MORE_FILES ) { res->resultMessage = buildResponseMessageType226(res->heapHandler); } else { res->resultMessage = concat(res->heapHandler , 2 , "426 accion no realizada, ocurrio un error" , CHARACTER_CRLF); } }
void Comm::put(char *buf, int length) { CRC crc = CRC(); crc_t code = crc.encode(buf, length); sendBytes(COMM_HEAD, COMM_HEAD_LEN); send((char *)&code, sizeof(crc_t)); send(buf, length); sendBytes(COMM_TAIL, COMM_TAIL_LEN); }
static void downloadFile (void) { if (makeDownloadFifo()) { int file = open(downloadPath, O_RDONLY); if (file != -1) { struct stat status; if (fstat(file, &status) != -1) { unsigned char buffer[0X400]; const unsigned char *address = buffer; int count = 0; while (1) { const unsigned char *newline; if (!count) { count = read(file, buffer, sizeof(buffer)); if (!count) { static const unsigned char fileTrailer[] = {0X1A}; sendBytes(fileTrailer, sizeof(fileTrailer)); break; } if (count == -1) { logSystemError("Download file read"); break; } address = buffer; } if ((newline = memchr(address, '\n', count))) { static const unsigned char lineTrailer[] = {CR, LF}; size_t length = newline - address; if (!sendBytes(address, length++)) break; if (!sendBytes(lineTrailer, sizeof(lineTrailer))) break; address += length; count -= length; } else { if (!sendBytes(address, count)) break; count = 0; } } } else { logSystemError("Download file status"); } if (close(file) == -1) { logSystemError("Download file close"); } } else { logSystemError("Download file open"); } } else { logMessage(LOG_WARNING, "Download path not specified."); } }
int I2C::sendESCs(int data[], int num) { //convert int to bytes[2] //declare array of unions and fill up union int_byt { uint8_t b[2]; int i; } *data2 = new int_byt[num]; for (int i=0; i<num; i++) { data2[i].i = data[i]; } //convert to table of bytes uint8_t *buf = new uint8_t[2*num]; for (int i=0; i<num; i++) { for (int ib=0; ib<2; ib++) { buf[2*i+ib] = data2[i].b[ib]; } } int count; do { count = sendBytes(buf, (uint8_t) 2*num); //if (count == 0 ) exit(0); usleep(1000); }while ( count != 2*num ); }
void doOfflineRetrieveFile(ClientThreadResource * res , ListenSocket clientSocket ,RuntimeErrorValidator * validator){ HANDLE existingFile = getReadFileHandle(res->argument , res->heapHandler); char readBuffer[65536]; int bytesRead; BOOL readFlag; ZeroMemory(readBuffer, 65536); readFlag = ReadFile( existingFile , readBuffer , 65536 , &bytesRead , NULL ); while( readFlag && bytesRead > 0){ if( sendBytes(clientSocket , readBuffer , bytesRead) < bytesRead ){ setError(validator , "Se han enviado menos bytes de los que se han leido"); break; } ZeroMemory(readBuffer, 65536); readFlag = ReadFile( existingFile , readBuffer , 65536 , &bytesRead , NULL ); } CloseHandle(existingFile); closeSocket(res->dataSocket); if (!hasError(validator)) { res->resultMessage = buildResponseMessageType226(res->heapHandler); } else { res->resultMessage = buildResponseMessageType426(res->heapHandler); } }
void DialogSocket::sendTelnetCommand(unsigned char command) { unsigned char buffer[2]; buffer[0] = TELNET_IAC; buffer[1] = command; sendBytes(buffer, 2); }
/* * ======== main ======== */ void loop() { unsigned char SlaveAddress; //Contains device address unsigned char command; //Contains the access command unsigned int data; //Contains data value // Activate Grace-generated configuration headPhoneGpio_init(); SlaveAddress = SA << 1; //Set device address command = RAM_Access | RAM_To; //Form RAM access command + RAM address //P1DIR &= ~0x01; mdelay(300); //interrupt_init(); iic_gpio_init(); WakeUpSensor(); timer_init(); // >>>>> Fill-in user code here <<<<< //_BIS_SR(LPM0_bits + GIE); for (;;) { data=readTemp();//MemRead((MLX90615_ADDR>>1),0x27); if(data!=-1) { data=data * 2 - 27315; buffer[0]=TOKEN_CMD_OBJ_TMP; buffer[1]=(data>>8)&0xff; buffer[2]=(data)&0xff; buffer[3]=~(buffer[0]+buffer[1]+buffer[2])-1; sendBytes(buffer,4); } // readTemp(); }
void HatchetSipPlugin::webSocketConnected() { tLog() << Q_FUNC_INFO << "WebSocket connected"; if ( m_token.isEmpty() || !m_account->credentials().contains( "username" ) ) { tLog() << Q_FUNC_INFO << "access token or username is empty, aborting"; disconnectPlugin(); return; } hatchetAccount()->setConnectionState( Tomahawk::Accounts::Account::Connected ); m_sipState = AcquiringVersion; /* m_uuid = QUuid::createUuid().toString(); QCA::SecureArray sa( m_uuid.toLatin1() ); QCA::SecureArray result = m_publicKey->encrypt( sa, QCA::EME_PKCS1_OAEP ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "uuid:" << m_uuid << ", size of uuid:" << m_uuid.size() << ", size of sa:" << sa.size() << ", size of result:" << result.size(); */ QVariantMap nonceVerMap; nonceVerMap[ "version" ] = VERSION; //nonceVerMap[ "nonce" ] = QString( result.toByteArray().toBase64() ); sendBytes( nonceVerMap ); }
void MultiplexedSocket::closeStream(const MultiplexedSocketPtr& thus,const Stream::StreamID&sid,TCPStream::TCPStreamControlCodes code) { RawRequest closeRequest; closeRequest.originStream=Stream::StreamID();//control packet closeRequest.unordered=false; closeRequest.unreliable=false; closeRequest.data=ASIOSocketWrapper::constructControlPacket(code,sid); sendBytes(thus,closeRequest); }
/** Send raw bytes without encoding with msgpack. * param: string to send. */ int lk::Socket::send(lua_State *L) { // <string> size_t size; const char *data = luaL_checklstring(L, -1, &size); // printf("send string (%lu bytes)\n", size); // send raw bytes return sendBytes(data, size); }
void DialogSocket::sendTelnetCommand(unsigned char command, unsigned char arg) { unsigned char buffer[3]; buffer[0] = TELNET_IAC; buffer[1] = command; buffer[2] = arg; sendBytes(buffer, 3); }
/* * Send packet header followed by data. */ jint shmemBase_sendPacket(SharedMemoryConnection *connection, struct Packet *packet) { jint length = 0; struct PacketData *data; CHECK_ERROR(sendBytes(connection, &packet->type.cmd.id, sizeof(jint))); CHECK_ERROR(sendBytes(connection, &packet->type.cmd.flags, sizeof(jbyte))); if (packet->type.cmd.flags & FLAGS_Reply) { CHECK_ERROR(sendBytes(connection, &packet->type.reply.errorCode, sizeof(jshort))); } else { CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmdSet, sizeof(jbyte))); CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmd, sizeof(jbyte))); } data = &(packet->type.cmd.data); do { length += data->length; data = data->next; } while (data != NULL); CHECK_ERROR(sendBytes(connection, &length, sizeof(jint))); data = &(packet->type.cmd.data); do { CHECK_ERROR(sendBytes(connection, data->data, data->length)); data = data->next; } while (data != NULL); return SYS_OK; }
/* * Send packet header followed by data. */ jint shmemBase_sendPacket(SharedMemoryConnection *connection, const jdwpPacket *packet) { jint data_length; clearLastError(); CHECK_ERROR(sendBytes(connection, &packet->type.cmd.id, sizeof(jint))); CHECK_ERROR(sendBytes(connection, &packet->type.cmd.flags, sizeof(jbyte))); if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { CHECK_ERROR(sendBytes(connection, &packet->type.reply.errorCode, sizeof(jshort))); } else { CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmdSet, sizeof(jbyte))); CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmd, sizeof(jbyte))); } data_length = packet->type.cmd.len - 11; SHMEM_GUARANTEE(data_length >= 0); CHECK_ERROR(sendBytes(connection, &data_length, sizeof(jint))); if (data_length > 0) { CHECK_ERROR(sendBytes(connection, packet->type.cmd.data, data_length)); } return SYS_OK; }
void testFileTransfer(){ MpsHeader header; header.payloadDescriptor = '0'; memcpy(header.descriptorId , generateRandomKey(16) , 16); //strcpy(header.descriptorId , generateRandomKey(16)); File * file1 = fopen("/home/gonzalo/images/anonimo.jpg" , "r"); char readingBuffer[1024]; char buffer[65536]; char * opName = "snd_img1"; int offset = 0; while(! feof(file1) && header.payloadDescriptor == '0'){ bzero(buffer , 65536); fread(readingBuffer , sizeof(char) , 1024 , file1); FileBlock * block = getFileBlock(readingBuffer); header.payloadDescriptor = 'b'; header.payloadSize = sizeof(FileBlock) + strlen("snd_img1"); memcpy(buffer , &header , sizeof(MpsHeader)); offset += sizeof(MpsHeader); memcpy(buffer + 21 , opName , strlen("snd_img1")); offset += strlen("snd_img1"); memcpy(buffer + 29 , block , sizeof(FileBlock)); offset += sizeof(FileBlock); sendBytes(getFileSystemConnection() , buffer , offset ); recv(getFileSystemConnection() , &header , sizeof(MpsHeader) , 0); } header.payloadSize = 0; header.payloadDescriptor = 'a'; sendBytes(getFileSystemConnection() , &header , sizeof(MpsHeader)); fclose(file1); }
static BOOL initSession( SOCKET sock ) { BYTE buffer[ 1024 ]; DWORD length; BOOL aes256 = FALSE; aes256 = (aesMaxKey >= 256); buffer[ 0 ] = aes256 ? 1 : 0; if ( ! (length = encodePK( sizeof( buffer ) - 1, &buffer[1] )) ) return( FALSE ); if ( verbose ) { printf( "Session Initiation: \n" ); hexDump( length + 1, buffer ); } if ( ! sendBytes( sock, buffer, length + 1 ) ) return( FALSE ); if ( ! receiveBytes( sock, buffer, sizeof( buffer ), &length ) ) return( FALSE ); if ( ! length ) { fprintf( stderr, "No session response from server\n" ); return( FALSE ); } if ( verbose ) { printf( "Session Response: \n" ); hexDump( length, buffer ); } switch( buffer[ 0 ] ) { case 0 : aes256 = FALSE; break; case 1 : if ( aes256 ) break; /* ** Fall through for unsupported AES key length. */ default: fprintf( stderr, "Invalid AES key length returned: %d\n", buffer[0] ); return( FALSE ); } if ( ! decodeSK( aes256, length - 1, &buffer[1] ) ) return( FALSE ); return( TRUE ); }
int8_t MessageIface::sendPacket( uint8_t msg_type, uint8_t *data, uint8_t length ) { uint8_t header[3]; header[0] = kStartByte; // const defined by packet_finder.c header[1] = length; header[2] = msg_type; sendBytes(header, 3); sendBytes(data, length); uint8_t footer[2]; uint16_t crc; crc = MakeCrc(&(header[1]), 2); crc = ArrayUpdateCrc(crc, data, length); footer[0] = crc & 0x00FF; footer[1] = crc >> 8; sendBytes(footer, 2); return(1); }
void baja_de_personaje(char id_pj,t_nivel* nivel,ITEM_NIVEL** listaItems){ log_info(logger, "Ejecutando [baja_de_personaje]..."); t_list* recursos_a_orquestador = list_create(); log_info(logger, "[baja_de_personaje] Cargando recursos a orquestador..."); cargarRecursosAOrquestador(recursos_a_orquestador,id_pj,nivel->personajes_deadlock); //int* socket = socket_create_sin_puerto(); int* socket = socket_create(15000, logger); log_trace(logger, "Procesando [conectarse_a_orquestador]..."); if (socket_connect_with_retry(socket, nivel->ip, nivel->puerto, logger) < 0) { log_error(logger, "[baja_de_personaje] No pudo conectar"); exit(EXIT_FAILURE); } log_trace(logger, "Saliendo [baja_de_personaje]..."); int id_nivel = parsear_nivel(nivel->nombre); t_stream* stream=lista_liberados_serialize(recursos_a_orquestador,id_nivel); log_info(logger, "[baja_de_personaje] Sending bytes..."); sendBytes(socket,stream->data,stream->size, logger); log_info(logger, "[baja_de_personaje] Borrando item para id_pj=[%c]...", id_pj); BorrarItem(&nivel->lista_items,id_pj); liberarPersonaje(nivel->personajes_deadlock,id_pj); log_info(logger, "[baja_de_personaje] recibiendo del orquestador posibles personajes desbloqueados..."); char* data=receiveBytes(socket,sizeof(int)*2, logger); if(data!=NULL){ log_info(logger, "[baja_de_personaje] Deserializando data..."); t_header* header=(t_header*)deserializar_header(data); switch (header->tipo){ case NO_LIBERE: { log_info(logger, "[baja_de_personaje] Agregando a disponibles..."); agregarDisponibles(listaItems,recursos_a_orquestador); break; } case LIBERADOS: { log_info(logger, "[baja_de_personaje] Liberados -> Recibiendo del orquestador Personajes Desbloqueados..."); data = receiveBytes(socket,header->tamanio, logger); char* personajes = deserializar_liberados(data); actualizarPersonajesYActualizarDisponibles(personajes,nivel->personajes_deadlock,recursos_a_orquestador,listaItems); break; } } } log_info(logger, "[baja_de_personaje] cerrando socket=[%d]...", *socket); socket_close(socket, logger); log_info(logger, "Saliendo [baja_de_personaje]..."); }
// // sync() - "sync-up" with the VDIP board prior to issuing a command. This makes // sure that the board is ready for a command before interacting with it. // Granted there is still the possibility that some darned async data // could fill the VDIP buffer before the command after this sync. But // there isn't much we can do about that...alas. // // BIG NOTE - this routine doesn't have a timeout. The point here is // that if this routine can't get in sync with the board, then we have // insurmountable problems! In other words, major bummer. // // RETURNS: // false - not yet in sync, need to call it again to get in sync (and // go ahead and do other stuff in the mean-time, like reset // something else or blink an LED) // true - we're in sync with the VDIP - go ahead and issue a command // // ASSUMPTIONS: // - reset() will set _resetDelay and _resetTarget appropriately // bool VDIP::sync() { // note that we're using the "E" (echo) to sync - this is the same in // both short and extended command set - so this can be used during reset const char sBuffer[2] = { 'E', '\r' }; // check to see if we are still in reset delay if(_resetDelay) { if(millis() < _resetTarget) { flush(); // just keep flushing the VDIP output buffer return(false); // still in reset delay } // we just got out of reset delay, time to initialize the VDIP. // To do this, get in sync, then execute the init() command(s). _resetDelay = false; sync(); // RECURSIVE! init(); // we assume (rightly/wrongly) that we are in sync after this // so just return - no need to do it again below return(true); } // all reset-style processing is done above - at this point we're just in the // middle of operations looking to ensure that we're sync'd with the VDIP // the "new" sync is blocking style, that is, if the VDIP misbehavesw, then // it will never return...but if that is the case, we have bigger problems anyway. // Below, we send out the sync/echo command and simply wait for its return. // This has the same effect as a flush, by-the-way. sendBytes(2,sBuffer,0); // a blocking fsendBy of the sync/echo string while(true) { unsigned char RChar, prevRChar; if(recv(&RChar)) { if(RChar == '\r' && prevRChar == 'E') { // we're sync'd up here! return(true); } prevRChar = RChar; } } // we never get here }
void doOnlineListFiles(ClientThreadResource * res , ListenSocket clientSocket , RuntimeErrorValidator * validator){ char * pathToList = res->relativeWorkingDir; List contents = callKssOperationList(res->heapHandler , pathToList , validator); Iterator * ite = buildIterator(contents , res->heapHandler); while(hasMoreElements(ite)){ if( equalsStrings(res->relativeWorkingDir , "/")){ char * vdaName = next(ite); char * msg = concat(res->heapHandler, 3, "drwxrwxrwx 1 ftp ftp 4096 Jul 11 2011 ", vdaName , CHARACTER_CRLF); sendBytes(clientSocket , msg , (int) strlen(msg)); }else{ char * serializedContent = next(ite); List files = deserializeList(serializedContent ,res->heapHandler); Iterator * ite = buildIterator(files , res->heapHandler); char * size = hasMoreElements(ite) ? next(ite) : NULL; char * fileName = hasMoreElements(ite) ? next(ite) : NULL; char * msg = concat(res->heapHandler, 5 , "-rwxrwxrwx 1 ftp ftp " , size , "Jul 11 2011 " , fileName , CHARACTER_CRLF); sendBytes(clientSocket , msg , (int) strlen(msg)); } } if(hasError(validator)){ res->resultMessage = buildResponseMessageType426(res->heapHandler); }else{ res->resultMessage = buildResponseMessageType226(res->heapHandler); } }
static TSS2_RC tctiSendBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, const unsigned char *data, int len ) { TSS2_RC ret = TSS2_RC_SUCCESS; #ifdef DEBUG_SOCKETS TCTI_LOG( tctiContext, NO_PREFIX, "Send Bytes to socket #0x%x: \n", sock ); TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, (UINT8 *)data, len ); #endif ret = sendBytes( sock, data, len); if (ret != TSS2_RC_SUCCESS) TCTI_LOG( tctiContext, NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n", sock, WSAGetLastError() ); return ret; }
void sendMpsHandshake(MpsHandshake * hand , ListenSocket l , RuntimeErrorValidator * v){ MpsHeader header; memcpy(header.descriptorId , hand->descriptorId , MPS_FIELD_LENGTH_DESCRIPTOR_ID); header.payloadDescriptor = hand->statusCode; header.payloadSize = 0; int bytesSended = sendBytes(l , &header , sizeof(MpsHeader)); if( bytesSended <= 0 ){ setError(v , "No se han podido enviar bytes en el handshake"); } }
TITANIUM_FUNCTION(UDP, sendBytes) { ENSURE_OPTIONAL_UINT_AT_INDEX(port, 0, 0); ENSURE_OPTIONAL_STRING_AT_INDEX(host, 1, ""); ENSURE_OPTIONAL_ARRAY_AT_INDEX(js_data, 2); std::vector<std::uint8_t> data; const auto length = js_data.GetLength(); for (uint32_t i = 0; i < length; i++) { data.push_back(static_cast<std::uint8_t>(static_cast<std::uint32_t>(js_data.GetProperty(i)))); } sendBytes(port, host, data); return get_context().CreateUndefined(); }
int I2C::sendInt(int data) { //convert int to bytes[2] union Sharedblock { uint8_t b[2]; int i; } data_u; data_u.i=data; return sendBytes(data_u.b,2); }
void doOnlineRetrieveFile(ClientThreadResource * res , ListenSocket clientSocket , RuntimeErrorValidator * validator){ FileBlock * block = NULL; int handleId = callKssOperationStartReadingProcess(res->heapHandler , res->argument , validator); if (hasError(validator)) { res->resultMessage = buildResponseMessageType426(res->heapHandler); return; } block = callKssOperationRead(res->heapHandler); while(block != NULL){ if(block->sector1.dataLength > 0){ sendBytes(res->dataSocket , block->sector1.data , block->sector1.dataLength); if(block->sector2.dataLength > 0){ sendBytes(res->dataSocket , block->sector2.data , block->sector2.dataLength); } } block = callKssOperationRead(res->heapHandler); } callKssOperationCloseFile(res->heapHandler , handleId , validator); if (!hasError(validator)) { res->resultMessage = buildResponseMessageType226(res->heapHandler); } else { res->resultMessage = buildResponseMessageType426(res->heapHandler); } }
void iPodSerial::sendCommandWithLength( size_t length, const byte *pData) { #if defined(IPOD_SERIAL_DEBUG) if (pDebugPrint) { pDebugPrint->print("Sending command of length: "); pDebugPrint->println(length, DEC); } #endif sendHeader(); sendLength(length); sendBytes(length, pData); sendChecksum(); }
// // init() - initializes the VDIP. This is only done after a reset/sync. Anything that // needs to be done to get the VDIP ready for operations is done here. // Given the importance of init() it blocks. That is, if it doesn't return // we're in big trouble anyway. // // This routine assumes that we're in sync. // void VDIP::init() { // the only thing we need to do here is go into shortened command mode // we are, by default, in binary value mode already upon reset so we don't // need to deal with that. Note, by-the-way, that this command works in // either extended or shortened command mode. const char sBuffer[4] = { 'S', 'C', 'S', '\r' }; unsigned char rBuffer[1]; (void)sendBytes(4,sBuffer,0); // just blocks waiting to send while(!recv(rBuffer)) { // spin around waiting for first return byte } while(rBuffer[0] != '\r') { // will potentially block waiting for '\r' recv(rBuffer); } }
static int sendData (unsigned char line, unsigned char column, unsigned char count) { unsigned char data[5 + count]; unsigned char *target = data; unsigned char *source = &targetImage[line][column]; *target++ = 0XFF; *target++ = line + 1; *target++ = (line == cursorRow)? cursorColumn+1: 0; *target++ = column + 1; *target++ = count; logBytes(LOG_DEBUG, "Output dots", source, count); target = translateOutputCells(target, source, count); count = target - data; logBytes(LOG_DEBUG, "LogText write", data, count); if (checkData(data, count)) { if (sendBytes(data, count)) { return 1; } } return 0; }
TSS2_RC SocketSendSessionEnd( TSS2_TCTI_CONTEXT *tctiContext, /* in */ UINT8 tpmCmdServer ) { UINT32 tpmSendCommand = TPM_SESSION_END; // Value for "send command" to MS simulator. SOCKET sock; if( tpmCmdServer ) { sock = TCTI_CONTEXT_INTEL->tpmSock; } else { sock = TCTI_CONTEXT_INTEL->otherSock; } tpmSendCommand = CHANGE_ENDIAN_DWORD(tpmSendCommand); sendBytes( sock, (char *)&tpmSendCommand, 4 ); return( TSS2_RC_SUCCESS ); }