/* parsing lists {{{*/ if(service) { xmlNodePtr memberships = findNode(service->children, "Memberships", 1); xmlNodePtr ms; xmlNodePtr role; xmlNodePtr members, member; xmlNodePtr pname; xmlNodePtr type; xmlNodePtr lastchange; xmlChar *content; int flag = 0; lastchange = findNode(service->children, "LastChange", 1); content = xmlNodeGetContent(lastchange); cl->lastchange = strdup((char*)content); DMSG(stderr, "Contact: lastchange = %s\n", cl->lastchange); if(!memberships) { fprintf(stderr, "NULL membership\n"); count = 0; goto cleanup; } for(ms=memberships->children;ms;ms=ms->next) { int ctype = 1; if(!ms->children) continue; role = findNode(ms->children, "MemberRole", 1); if(!role) { fprintf(stderr, "Null role\n"); count = 0; goto cleanup; } members = findNode(role, "Members", 1); if(!members) continue; if(xmlStrEqual(role->children->content, (xmlChar*)"Allow")) flag = 3; else if(xmlStrEqual(role->children->content, (xmlChar*)"Block")) flag = 4; else continue; for(member=members->children;member;member=member->next) { Contact *c; type = findNode(member->children, "Type", 1); content = xmlNodeGetContent(type); if(!content) { fprintf(stderr, "NULL Type\n"); continue; } if(xmlStrEqual(content, (xmlChar*)"Passport")) { pname = findNode(member->children, "PassportName", 1); ctype = 1; } else if(xmlStrEqual(content, (xmlChar*)"Email")) { pname = findNode(member->children, "Email", 1); ctype = 32; } else continue; xmlFree(content); if(!pname) { fprintf(stderr, "NULL PassportName or Email\n"); continue; } content = xmlNodeGetContent(pname); if(content) { char name[32]; char domain[32]; if(sscanf((char*)content, "%[^@]@%s", name, domain) != 2) { fprintf(stderr, "parse contact: malformed email: %s\n", content); continue; } c = contact_new((char*)content); c->name = strdup(name); c->type = ctype; c->status = NA; c->inlist |= flag; c->domain = NULL; /* should be filled during sort */ cl_append_contact(cl, c, name, domain); xmlFree(content); count++; } } } }/*}}}*/ DMSG(stderr, "parsed contact count: %d\n", count); cleanup: cl->flag &= ~CL_INITLIST; return count; }/*}}}*/ int _cl_do_soapreq_ab(CL *cl)/*{{{*/ { TCPClient *client; char *req = NULL; char *header; char buf[512]; int ret, len; char *ptr = NULL; client = tcpclient_new("contacts.msn.com", 80); ret = _cl_load_soapreq_ab(cl, cl->ablastchange, &req, TRUE); if(ret) { tcpclient_connect(client); header = (char*)xmalloc(strlen(ab_request_header) + 32); DMSG(stderr, "sending ab request\n"); len = sprintf(header, "%s%d\r\n\r\n", ab_request_header, ret); if(tcpclient_send(client, header, len) <= 0) goto cleanup; if(tcpclient_send(client, req, ret) <= 0) goto cleanup; len = tcpclient_recv_header(client, &ptr); /* header */ if(ptr) { HTTPHeader *header; xmlDocPtr doc; xmlParserCtxtPtr ctxt; FILE *fp; DMSG(stderr, "AB response header:\n%s", ptr); header = http_parse_header(ptr); len = header->content_length; DMSG(stderr, "Length: %d\n", len); http_header_destroy(header); memset(buf, 0, sizeof(buf)); fp = fopen("addressbook.xml", "w"); fprintf(fp, buf); len -= (ret = tcpclient_recv(client, buf, sizeof(buf)-1)); ctxt = xmlCreatePushParserCtxt(NULL, NULL, buf, ret, "addressbook.xml"); fprintf(fp, buf); if(ctxt == NULL) { fprintf(stderr, "failed to create parser context"); return 0; } while(len > 0) { memset(buf, 0, sizeof(buf)); len -= (ret=tcpclient_recv(client, buf, sizeof(buf)-1)); fprintf(fp, buf); xmlParseChunk(ctxt, buf, ret, 0); } fclose(fp); xmlParseChunk(ctxt, buf, 0, 1); tcpclient_destroy(client); client = NULL; doc = ctxt->myDoc; len = ctxt->wellFormed; xmlFreeParserCtxt(ctxt); //count += _cl_parse_contacts(cl, doc); xmlFreeDoc(doc); xmlCleanupParser(); DMSG(stderr, "addressbook xml parsing done: %s\n", len?"good":"malformed"); xfree(ptr); } else { DMSG(stderr, "ab: no header found\n\r"); } } else { fprintf(stderr, "failed to load abreq\n"); } cleanup: xfree(header); return 0; }/*}}}*/ int cl_load_contacts(CL *cl, const char* file)/*{{{*/ { int ret; xmlDocPtr doc; xmlNodePtr root; xmlNodePtr contact; xmlNodePtr node; xmlChar *content; doc = xmlReadFile(file, NULL, 0); if (doc == NULL) { fprintf(stderr, "Failed to parse %s\n", file); return 0; } ret = 0; root = xmlDocGetRootElement(doc); contact = findNode(root->children, "contact", 3); #define READSTR(dst,elem) node = findNode(contact->children, elem, 1); \ content = xmlNodeGetContent(node); \ dst = strdup((char*)content); \ xmlFree(content) #define READINT(dst, elem) node = findNode(contact->children, elem, 1); \ content = xmlNodeGetContent(node); \ dst = atoi((char*)content); \ xmlFree(content) for(;contact;contact=contact->next) { Contact *c; node = findNode(contact->children, "nick", 1); content = xmlNodeGetContent(node); c = contact_new((char*)content); xmlFree(content); READSTR(c->name, "name"); READSTR(c->PSM, "PSM"); READINT(c->inlist, "inlist"); READINT(c->type, "type"); c->status = NA; node = findNode(contact->children, "domain", 1); content = xmlNodeGetContent(node); c->domain = NULL; /* should be filled during sort */ cl_append_contact(cl, c, c->name, (char*)content); xmlFree(content); ret++; } node = findNode(root->children, "lastchange", 3); if(node) { content = xmlNodeGetContent(node); cl->lastchange = strdup((char*)content); xmlFree(content); } xmlFreeDoc(doc); return ret; }/*}}}*/ void cl_save(CL *cl, const char *filename)/*{{{*/ { Contact *c; FILE *fp = fopen(filename, "w"); if(!fp) return; fprintf(fp, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"); fprintf(fp, "<contactinfo>"); fprintf(fp, "<contacts>"); for(c=cl->list;c;c=c->g_next) { fprintf(fp, "<contact>"); fprintf(fp, "<name>%s</name>", c->name); fprintf(fp, "<nick>%s</nick>", c->nick); fprintf(fp, "<PSM>%s</PSM>", c->PSM?c->PSM:""); fprintf(fp, "<domain>%s</domain>", c->domain); fprintf(fp, "<inlist>%d</inlist>", c->inlist); fprintf(fp, "<type>%d</type>", c->type); fprintf(fp, "</contact>"); } fprintf(fp, "</contacts>"); if(cl->lastchange) fprintf(fp,"<lastchange>%s</lastchange>", cl->lastchange); if(cl->ablastchange) fprintf(fp,"<ablastchange>%s</ablastchange>", cl->ablastchange); fprintf(fp, "</contactinfo>"); fflush(fp); fclose(fp); }/*}}}*/ int _cl_do_soapreq_ms(CL *cl)/*{{{*/ { SSLClient *client; int ret; int len; int count = 0; char *req = NULL; char *header; char contactfile[64]; FILE *fp; header = (char*)xmalloc(strlen(ms_request_header) + 32); client = sslclient_new(DEFAULTSERVER, 443); if(!sslclient_connect(client)) return 0; /* connected */ MD5((unsigned char*)cl->account->username, strlen(cl->account->username), (unsigned char*)contactfile); sprintf(contactfile, "%x%x.xml", (unsigned char)contactfile[0], (unsigned char)contactfile[1]); if((fp=fopen(contactfile, "r"))) { DMSG(stderr, "loading cached contacts...\n"); if((count = cl_load_contacts(cl, contactfile))) ret = _cl_load_soapreq_ms(cl, cl->lastchange, &req, FALSE); else ret = _cl_load_soapreq_ms(cl, cl->lastchange, &req, TRUE); DMSG(stderr, "%d contacts loaded from cache...\n", count); fclose(fp); } else ret = _cl_load_soapreq_ms(cl, cl->lastchange, &req, TRUE); if(ret) { char buf[512] = {0}; char *ptr = NULL; xmlDocPtr doc; xmlParserCtxtPtr ctxt; FILE *fp; DMSG(stderr, "sending cl request\n"); /* send request */ len = sprintf(header, ms_request_header, ret); if(sslclient_send(client, header, len) <= 0) goto cleanup; if(sslclient_send(client, req, ret) <= 0) goto cleanup; DMSG(stderr, "getting cl response\n"); /* get response */ DMSG(stderr, "HEADER:\n"); len = sslclient_recv_header(client, &ptr); /* header */ if(ptr) { HTTPHeader *header; DMSG(stderr, ptr); header = http_parse_header(ptr); len = header->content_length; DMSG(stderr, "content length: %d\n", len); http_header_destroy(header); xfree(ptr); } else { DMSG(stderr, "no header found\n\r"); } memset(buf, 0, sizeof(buf)); fp = fopen("contacts.xml", "w"); len -= (ret = sslclient_recv(client, buf, sizeof(buf)-1)); ctxt = xmlCreatePushParserCtxt(NULL, NULL, buf, ret, "contacts.xml"); DMSG(stderr, "RESPONSE:\n"); fprintf(fp, buf); if(ctxt == NULL) { fprintf(stderr, "failed to create parser context"); return 0; } while(len > 0) { memset(buf, 0, sizeof(buf)); len -= (ret=sslclient_recv(client, buf, sizeof(buf)-1)); fprintf(fp, buf); xmlParseChunk(ctxt, buf, ret, 0); } fclose(fp); xmlParseChunk(ctxt, buf, 0, 1); sslclient_destroy(client, FALSE); client = NULL; doc = ctxt->myDoc; len = ctxt->wellFormed; xmlFreeParserCtxt(ctxt); count += _cl_parse_contacts(cl, doc); xmlFreeDoc(doc); xmlCleanupParser(); DMSG(stderr, "contact xml parsing done: %s\n", len?"good":"malformed"); } _cl_sort_contacts(cl); cl_save(cl, contactfile); cleanup: xfree(req); xfree(header); return count; }/*}}}*/
/* * Called when the instance of the TA is created. This is the first call in * the TA. */ TEE_Result TA_CreateEntryPoint(void) { DMSG("has been called"); return TEE_SUCCESS; }
/* * Called when a session is closed, sess_ctx hold the value that was * assigned by TA_OpenSessionEntryPoint(). */ void TA_CloseSessionEntryPoint(void *sess_ctx) { (void)&sess_ctx; /* Unused parameter */ DMSG("has been called"); }
/* * TA invokes some TA with parameter. * If some parameters are memory references: * - either the memref is inside TA private RAM: TA is not allowed to expose * its private RAM: use a temporary memory buffer and copy the data. * - or the memref is not in the TA private RAM: * - if the memref was mapped to the TA, TA is allowed to expose it. * - if so, converts memref virtual address into a physical address. */ static TEE_Result tee_svc_copy_param(struct tee_ta_session *sess, struct tee_ta_session *called_sess, uint32_t param_types, TEE_Param params[TEE_NUM_PARAMS], struct tee_ta_param *param, tee_paddr_t tmp_buf_pa[TEE_NUM_PARAMS], tee_mm_entry_t **mm) { size_t n; TEE_Result res; size_t req_mem = 0; size_t s; uint8_t *dst = 0; tee_paddr_t dst_pa, src_pa = 0; bool ta_private_memref[TEE_NUM_PARAMS]; param->types = param_types; if (params == NULL) { if (param->types != 0) return TEE_ERROR_BAD_PARAMETERS; memset(param->params, 0, sizeof(param->params)); } else { tee_svc_copy_from_user(sess, param->params, params, sizeof(param->params)); } if ((called_sess != NULL) && (called_sess->ctx->static_ta == NULL) && (called_sess->ctx->flags & TA_FLAG_USER_MODE) == 0) { /* * kernel TA, borrow the mapping of the calling * during this call. */ called_sess->calling_sess = sess; return TEE_SUCCESS; } for (n = 0; n < TEE_NUM_PARAMS; n++) { ta_private_memref[n] = false; switch (TEE_PARAM_TYPE_GET(param->types, n)) { case TEE_PARAM_TYPE_MEMREF_INPUT: case TEE_PARAM_TYPE_MEMREF_OUTPUT: case TEE_PARAM_TYPE_MEMREF_INOUT: if (param->params[n].memref.buffer == NULL) { if (param->params[n].memref.size != 0) return TEE_ERROR_BAD_PARAMETERS; break; } /* uTA cannot expose its private memory */ if (tee_mmu_is_vbuf_inside_ta_private(sess->ctx, (uintptr_t)param->params[n].memref.buffer, param->params[n].memref.size)) { s = TEE_ROUNDUP(param->params[n].memref.size, sizeof(uint32_t)); /* Check overflow */ if (req_mem + s < req_mem) return TEE_ERROR_BAD_PARAMETERS; req_mem += s; ta_private_memref[n] = true; break; } if (!tee_mmu_is_vbuf_outside_ta_private(sess->ctx, (uintptr_t)param->params[n].memref.buffer, param->params[n].memref.size)) return TEE_ERROR_BAD_PARAMETERS; if (tee_mmu_user_va2pa(sess->ctx, (void *)param->params[n].memref.buffer, (void **)&src_pa) != TEE_SUCCESS) return TEE_ERROR_BAD_PARAMETERS; param->param_attr[n] = tee_mmu_user_get_cache_attr( sess->ctx, (void *)param->params[n].memref.buffer); param->params[n].memref.buffer = (void *)src_pa; break; default: break; } } if (req_mem == 0) return TEE_SUCCESS; /* Allocate section in secure DDR */ *mm = tee_mm_alloc(&tee_mm_sec_ddr, req_mem); if (*mm == NULL) { DMSG("tee_mm_alloc TEE_ERROR_GENERIC"); return TEE_ERROR_GENERIC; } /* Get the virtual address for the section in secure DDR */ res = tee_mmu_kmap(tee_mm_get_smem(*mm), req_mem, &dst); if (res != TEE_SUCCESS) return res; dst_pa = tee_mm_get_smem(*mm); for (n = 0; n < 4; n++) { if (ta_private_memref[n] == false) continue; s = TEE_ROUNDUP(param->params[n].memref.size, sizeof(uint32_t)); switch (TEE_PARAM_TYPE_GET(param->types, n)) { case TEE_PARAM_TYPE_MEMREF_INPUT: case TEE_PARAM_TYPE_MEMREF_INOUT: if (param->params[n].memref.buffer != NULL) { res = tee_svc_copy_from_user(sess, dst, param->params[n]. memref.buffer, param->params[n]. memref.size); if (res != TEE_SUCCESS) return res; param->param_attr[n] = tee_mmu_kmap_get_cache_attr(dst); param->params[n].memref.buffer = (void *)dst_pa; tmp_buf_pa[n] = dst_pa; dst += s; dst_pa += s; } break; case TEE_PARAM_TYPE_MEMREF_OUTPUT: if (param->params[n].memref.buffer != NULL) { param->param_attr[n] = tee_mmu_kmap_get_cache_attr(dst); param->params[n].memref.buffer = (void *)dst_pa; tmp_buf_pa[n] = dst_pa; dst += s; dst_pa += s; } break; default: continue; } } tee_mmu_kunmap(dst, req_mem); return TEE_SUCCESS; }
int main() { int afd, pfd, cfd; char rbuff[GBUFFSIZE]; size_t buff_len; int atlen = strlen(AT_PREFIX); gid_t jgid; /* make socket unreadable */ umask( 0777 ); /* get unix domain socket and pts */ afd = get_audio_socket(); pfd = get_pts_socket(); jgid= get_jpolly_gid(); /* only allow write access to the media user */ chown(SOCKET_PATH, USER_MEDIA, jgid); chmod(SOCKET_PATH, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP ); /* drop root */ setgid(jgid); setuid(USER_MEDIA); if(setuid(0) != -1) xdie("failed to drop root!"); /* terminates process if modem is stuck */ signal(SIGALRM, suicide); DMSG("socket setup finished. afd=%d, pfd=%d", afd, pfd); while( (cfd = accept(afd, NULL, NULL)) ) { /* read incomding data: we expect something like this: path,40,5,3,0,0,1,3,0,1,0,1,2,13 ..but we need.. AT+XDRV=40,5,3,0,0,1,3,0,1,0,1,2,13 the AT command string is 3 bytes longer, so we read to rbuff[3] and overwrite the rest afterwards */ memset(&rbuff, 0, GBUFFSIZE); buff_len = 3+read(cfd, &rbuff[3], GBUFFSIZE-3-2); /* -3 = offset, -2 = \r\0 */ memcpy(&rbuff, AT_PREFIX, atlen); /* add AT+XDRV= */ memcpy(&rbuff[buff_len], "\r\0", 2); /* terminate string */ /* send command to modem if it looks ok */ if(buff_len == TERM_LEN && memcmp(&rbuff, TERM_MAGIC, TERM_LEN) == 0) { DMSG("Poison cracker received, commiting suicide in %d seconds", TERM_DELAY); sleep(TERM_DELAY); xdie("terminating"); } else if(buff_len >= CALLVOLUME_CMDLEN && at_args_sane(&rbuff[atlen], buff_len-atlen) == 1) { alarm(AT_TIMEOUT); send_xdrv_command(rbuff, pfd); alarm(0); } else { DMSG("silently dropping invalid command with %d bytes len", buff_len); } close(cfd); } DMSG("exiting, accept returned false on fd %d", afd); close(afd); close(pfd); xdie("terminating"); return 0; }
static TEE_Result alloc_benchmark_buffer(uint32_t type, TEE_Param p[TEE_NUM_PARAMS]) { TEE_Result res; if ((TEE_PARAM_TYPE_GET(type, 0) != TEE_PARAM_TYPE_VALUE_INOUT) || (TEE_PARAM_TYPE_GET(type, 1) != TEE_PARAM_TYPE_VALUE_INPUT) || (TEE_PARAM_TYPE_GET(type, 2) != TEE_PARAM_TYPE_NONE) || (TEE_PARAM_TYPE_GET(type, 3) != TEE_PARAM_TYPE_NONE)) { return TEE_ERROR_BAD_PARAMETERS; } mutex_lock(&bench_reg_mu); /* Check if we have already registered buffer */ if (bench_ts_global) { EMSG(TA_PRINT_PREFIX "timestamp buffer was already registered"); mutex_unlock(&bench_reg_mu); return TEE_ERROR_BAD_STATE; } bench_ts_size = sizeof(struct tee_ts_global) + p[1].value.a * sizeof(struct tee_ts_cpu_buf); if (!bench_ts_size) { EMSG(TA_PRINT_PREFIX "invalid timestamp buffer size"); mutex_unlock(&bench_reg_mu); return TEE_ERROR_BAD_STATE; } bench_mobj = thread_rpc_alloc_global_payload(bench_ts_size); if (!bench_mobj) { EMSG(TA_PRINT_PREFIX "can't create mobj for timestamp buffer"); mutex_unlock(&bench_reg_mu); return TEE_ERROR_OUT_OF_MEMORY; } bench_ts_global = (struct tee_ts_global *)mobj_get_va(bench_mobj, 0); if (!bench_ts_global) { thread_rpc_free_global_payload(bench_mobj); bench_mobj = NULL; mutex_unlock(&bench_reg_mu); return TEE_ERROR_BAD_STATE; } memset((void *)bench_ts_global, 0, bench_ts_size); bench_ts_global->cores = p[1].value.a; DMSG(TA_PRINT_PREFIX "allocated timestamp buffer, addr = %p", (void *)bench_ts_global); mutex_unlock(&bench_reg_mu); /* Send back to the optee linux kernel module */ res = rpc_reg_global_buf(OPTEE_MSG_RPC_CMD_BENCH_REG_NEW, virt_to_phys((void *)bench_ts_global), bench_ts_size); p[0].value.a = virt_to_phys((void *)bench_ts_global); p[0].value.b = bench_ts_size; return res; }
static void destroy_ta(void) { DMSG("destroy entry point for static ta \"%s\"", TA_NAME); }
void device::close_cmd(int secondary_address) { DMSG("> iec_close"); secondary_command( CMD_CLOSE(secondary_address), false ); DMSG("< iec_close"); }
void device::data_listen(int secondary_address) { DMSG("> iec_data_listen"); secondary_command( CMD_DATA(secondary_address), false ); DMSG("< iec_data_listen"); }
void device::listen( int device ) { DMSG("> iec_listen"); command( CMD_LISTEN(device) ); DMSG("< iec_listen"); }
void device::open_cmd(int secondary_address) { DMSG("> iec_open"); secondary_command( CMD_OPEN(secondary_address), false ); DMSG("< iec_open"); }
void device::talk( int device ) { DMSG("> iec_talk"); command( CMD_TALK(device) ); DMSG("< iec_talk"); }
bool KeyDuino::readPassiveTargetID_B(uint8_t *uid, uint8_t *uidLength, uint16_t timeout) { pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET; pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later) pn532_packetbuffer[2] = PN532_ISO14443B; pn532_packetbuffer[3] = 0x00; //AFI if (HAL(writeCommand)(pn532_packetbuffer, 4)) { DMSG_STR("\nFailed writing"); return 0x0; // command failed } // read data packet if (HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer), timeout) < 0) { DMSG_STR("\nFailed reading response"); return 0x0; } /* ISO14443B card response should be in the following format: byte Description ------------------ ------------------------------------------ b0 Tags Found b1 Tag Number (only one used in this example) b2..13 ATQB b14 ATTRIB_RES Length b15..ATTRIB_RESLen ATTRIB_RES */ if (pn532_packetbuffer[0] != 1) return 0; inListedTag = pn532_packetbuffer[1]; /* ISO14443B ATQ_B format: byte Description ----- ------------------------------------------ b0 0x50 b1..4 PUPI b5..8 Application Data b9 Bit Rate Capacity b10 Max Frame Size/-4 Info b11 FWI/Coding Options */ uint8_t atqb[12]; DMSG("\nATQ_B: "); if (pn532_packetbuffer[2] == 0x50) { //Looking for the 0x50 to check if ATQ_B is well shaped for (uint8_t i = 0; i < 12; i++) { atqb[i] = pn532_packetbuffer[i+2]; DMSG_HEX(atqb[i]); } DMSG("\n"); } else //Sometimes there are remnant bytes, in that case just let it go ... return 0; DMSG_STR("\nATTRIB_RES: "); for (uint8_t i = 0; i < pn532_packetbuffer[14]; i++) { DMSG_HEX(pn532_packetbuffer[15 + i]); } DMSG("\n"); *uidLength = 4; this->_uidLen = 4; for (uint8_t i = 0; i < 4; i++) { uid[i] = atqb[1 + i]; this->_uid[i] = atqb[1 + i]; } return 1; }
int pscan_main(int argc UNUSED_PARAM, char **argv) { const char *opt_max_port = "1024"; /* -P: default max port */ const char *opt_min_port = "1"; /* -p: default min port */ const char *opt_timeout = "5000"; /* -t: default timeout in msec */ /* We estimate rtt and wait rtt*4 before concluding that port is * totally blocked. min rtt of 5 ms may be too low if you are * scanning an Internet host behind saturated/traffic shaped link. * Rule of thumb: with min_rtt of N msec, scanning 1000 ports * will take N seconds at absolute minimum */ const char *opt_min_rtt = "5"; /* -T: default min rtt in msec */ const char *result_str; len_and_sockaddr *lsap; int s; unsigned opt; unsigned port, max_port, nports; unsigned closed_ports = 0; unsigned open_ports = 0; /* all in usec */ unsigned timeout; unsigned min_rtt; unsigned rtt_4; unsigned start, diff; opt_complementary = "=1"; /* exactly one non-option */ opt = getopt32(argv, "cbp:P:t:T:", &opt_min_port, &opt_max_port, &opt_timeout, &opt_min_rtt); argv += optind; max_port = xatou_range(opt_max_port, 1, 65535); port = xatou_range(opt_min_port, 1, max_port); nports = max_port - port + 1; min_rtt = xatou_range(opt_min_rtt, 1, INT_MAX/1000 / 4) * 1000; timeout = xatou_range(opt_timeout, 1, INT_MAX/1000 / 4) * 1000; /* Initial rtt is BIG: */ rtt_4 = timeout; DMSG("min_rtt %u timeout %u", min_rtt, timeout); lsap = xhost2sockaddr(*argv, port); printf("Scanning %s ports %u to %u\n Port\tProto\tState\tService\n", *argv, port, max_port); for (; port <= max_port; port++) { DMSG("rtt %u", rtt_4); /* The SOCK_STREAM socket type is implemented on the TCP/IP protocol. */ set_nport(&lsap->u.sa, htons(port)); s = xsocket(lsap->u.sa.sa_family, SOCK_STREAM, 0); /* We need unblocking socket so we don't need to wait for ETIMEOUT. */ /* Nonblocking connect typically "fails" with errno == EINPROGRESS */ ndelay_on(s); DMSG("connect to port %u", port); result_str = NULL; start = MONOTONIC_US(); if (connect(s, &lsap->u.sa, lsap->len) == 0) { /* Unlikely, for me even localhost fails :) */ DMSG("connect succeeded"); goto open; } /* Check for untypical errors... */ if (errno != EAGAIN && errno != EINPROGRESS && errno != ECONNREFUSED ) { bb_perror_nomsg_and_die(); } diff = 0; while (1) { if (errno == ECONNREFUSED) { if (opt & 1) /* -c: show closed too */ result_str = "closed"; closed_ports++; break; } DERR("port %u errno %d @%u", port, errno, diff); if (diff > rtt_4) { if (opt & 2) /* -b: show blocked too */ result_str = "blocked"; break; } /* Can sleep (much) longer than specified delay. * We check rtt BEFORE we usleep, otherwise * on localhost we'll have no writes done (!) * before we exceed (rather small) rtt */ usleep(rtt_4/8); open: diff = MONOTONIC_US() - start; DMSG("write to port %u @%u", port, diff - start); if (write(s, " ", 1) >= 0) { /* We were able to write to the socket */ open_ports++; result_str = "open"; break; } } DMSG("out of loop @%u", diff); if (result_str) printf("%5u" "\t" "tcp" "\t" "%s" "\t" "%s" "\n", port, result_str, port_name(port)); /* Estimate new rtt - we don't want to wait entire timeout * for each port. *4 allows for rise in net delay. * We increase rtt quickly (rtt_4*4), decrease slowly * (diff is at least rtt_4/8, *4 == rtt_4/2) * because we don't want to accidentally miss ports. */ rtt_4 = diff * 4; if (rtt_4 < min_rtt) rtt_4 = min_rtt; if (rtt_4 > timeout) rtt_4 = timeout; /* Clean up */ close(s); } if (ENABLE_FEATURE_CLEAN_UP) free(lsap); printf("%u closed, %u open, %u timed out (or blocked) ports\n", closed_ports, open_ports, nports - (closed_ports + open_ports)); return EXIT_SUCCESS; }
bool active_protocol_c::cmdhandler(ipcr r) { switch(r.header().cmd) { case HA_CMD_STATUS: { commands_e c = (commands_e)r.get<int>(); cmd_result_e s = (cmd_result_e)r.get<int>(); if (c == AQ_SET_PROTO) { if (s == CR_OK) { priority = r.get<int>(); features = r.get<int>(); conn_features = r.get<int>(); auto desc = r.getastr(); auto desc_t = r.getastr(); audio_fmt.sampleRate = r.get<int>(); audio_fmt.channels = r.get<short>(); audio_fmt.bitsPerSample = r.get<short>(); auto w = syncdata.lock_write(); w().current_state = CR_OK; w().description.set_as_utf8(desc); w().description_t.set_as_utf8(desc_t); w().icon.setcopy(r.getastr()); ipcp->send(ipcw(AQ_SET_CONFIG) << w().data.config); ipcp->send(ipcw(AQ_SET_NAME) << (w().data.user_name.is_empty() ? prf().username() : w().data.user_name)); ipcp->send(ipcw(AQ_SET_STATUSMSG) << (w().data.user_statusmsg.is_empty() ? prf().userstatus() : w().data.user_statusmsg)); ipcp->send(ipcw(AQ_SET_AVATAR) << w().data.avatar); if (w().manual_cos != COS_ONLINE) set_ostate( w().manual_cos ); ipcp->send(ipcw(AQ_INIT_DONE)); if (0 != (w().data.options & active_protocol_data_s::O_AUTOCONNECT)) { ipcp->send(ipcw(AQ_ONLINE)); w().flags.set(F_ONLINE_SWITCH); } w().flags.set(F_SET_PROTO_OK); w.unlock(); gmsg<ISOGM_PROTO_LOADED> *m = TSNEW( gmsg<ISOGM_PROTO_LOADED>, id ); m->send_to_main_thread(); } else { return false; } } else if (c == AQ_SET_CONFIG || c == AQ_ONLINE) { if (s != CR_OK) { syncdata.lock_write()().current_state = s; goto we_shoud_broadcast_result; } } else { we_shoud_broadcast_result: DMSG( "cmd status: " << (int)c << (int)s ); gmsg<ISOGM_CMD_RESULT> *m = TSNEW(gmsg<ISOGM_CMD_RESULT>, id, c, s); m->send_to_main_thread(); } } break; case HQ_UPDATE_CONTACT: { gmsg<ISOGM_UPDATE_CONTACT> *m = TSNEW( gmsg<ISOGM_UPDATE_CONTACT> ); m->key.protoid = id; m->key.contactid = r.get<int>(); m->mask = r.get<int>(); m->pubid = r.getastr(); m->name = r.getastr(); m->statusmsg = r.getastr(); m->avatar_tag = r.get<int>(); m->state = (contact_state_e)r.get<int>(); m->ostate = (contact_online_state_e)r.get<int>(); m->gender = (contact_gender_e)r.get<int>(); /*int grants =*/ r.get<int>(); if (0 != (m->mask & CDM_MEMBERS)) // groupchat members { ASSERT( m->key.is_group() ); int cnt = r.get<int>(); m->members.reserve(cnt); for(int i=0; i<cnt; ++i) m->members.add( r.get<int>() ); } if (0 != (m->mask & CDM_DETAILS)) m->details = r.getastr(); m->send_to_main_thread(); } break; case HQ_MESSAGE: { gmsg<ISOGM_INCOMING_MESSAGE> *m = TSNEW(gmsg<ISOGM_INCOMING_MESSAGE>); m->groupchat.contactid = r.get<int>(); m->groupchat.protoid = m->groupchat.contactid ? id : 0; m->sender.protoid = id; m->sender.contactid = r.get<int>(); m->mt = (message_type_app_e)r.get<int>(); m->create_time = r.get<uint64>(); m->msgutf8 = r.getastr(); m->send_to_main_thread(); } break; case HQ_SAVE: syncdata.lock_write()().flags.set(F_SAVE_REQUEST); break; case HA_DELIVERED: { gmsg<ISOGM_DELIVERED> *m = TSNEW(gmsg<ISOGM_DELIVERED>, r.get<uint64>()); m->send_to_main_thread(); } break; case HA_CONFIG: { int sz; if (const void *d = r.get_data(sz)) { ts::md5_c md5; md5.update(d,sz); md5.done(); const void *md5r = r.read_data(16); if (md5r && 0 == memcmp(md5r, md5.result(), 16)) { auto w = syncdata.lock_write(); w().data.config.clear(); w().data.config.append_buf(d, sz); w().flags.set(F_CONFIG_OK|F_CONFIG_UPDATED); lastconfig = ts::Time::current(); } else { syncdata.lock_write()().flags.set(F_CONFIG_FAIL); } } } break; case HA_CONFIGURABLE: { auto w = syncdata.lock_write(); w().flags.set(F_CONFIGURABLE_RCVD); if (w().data.configurable.initialized) { configurable_s oldc = std::move(w().data.configurable); w.unlock(); set_configurable(oldc,true); } else { int n = r.get<int>(); for (int i = 0; i < n; ++i) { ts::str_c f = r.getastr(); ts::str_c v = r.getastr(); if (f.equals(CONSTASTR(CFGF_PROXY_TYPE))) w().data.configurable.proxy.proxy_type = v.as_int(); else if (f.equals(CONSTASTR(CFGF_PROXY_ADDR))) w().data.configurable.proxy.proxy_addr = v; else if (f.equals(CONSTASTR(CFGF_PROXY_ADDR))) w().data.configurable.proxy.proxy_addr = v; else if (f.equals(CONSTASTR(CFGF_SERVER_PORT))) w().data.configurable.server_port = v.as_int(); else if (f.equals(CONSTASTR(CFGF_IPv6_ENABLE))) w().data.configurable.ipv6_enable = v.as_int() != 0; else if (f.equals(CONSTASTR(CFGF_UDP_ENABLE))) w().data.configurable.udp_enable = v.as_int() != 0; w().data.configurable.initialized = true; } } } break; case HQ_AUDIO: { int gid = r.get<int>(); contact_key_s ck; ck.protoid = id | (gid << 16); // assume 65536 unique groups max ck.contactid = r.get<int>(); s3::Format fmt; fmt.sampleRate = r.get<int>(); fmt.channels = r.get<short>(); fmt.bitsPerSample = r.get<short>(); int dsz; const void *data = r.get_data(dsz); auto rd = syncdata.lock_read(); float vol = rd().volume; int dsp_flags = rd().dsp_flags; rd.unlock(); int dspf = 0; if (0 != (dsp_flags & DSP_SPEAKERS_NOISE)) dspf |= fmt_converter_s::FO_NOISE_REDUCTION; if (0 != (dsp_flags & DSP_SPEAKERS_AGC)) dspf |= fmt_converter_s::FO_GAINER; g_app->mediasystem().play_voice(ts::ref_cast<uint64>(ck), fmt, data, dsz, vol, dspf); /* ts::Time t = ts::Time::current(); static int cntc = 0; static ts::Time prevt = t; if ((t-prevt) >= 0) { prevt += 1000; DMSG("ccnt: " << cntc); cntc = 0; } ++cntc; */ } break; case HQ_STREAM_OPTIONS: { int gid = r.get<int>(); contact_key_s ck; ck.protoid = id | (gid << 16); // assume 65536 unique groups max ck.contactid = r.get<int>(); int so = r.get<int>(); ts::ivec2 sosz; sosz.x = r.get<int>(); sosz.y = r.get<int>(); gmsg<ISOGM_PEER_STREAM_OPTIONS> *m = TSNEW(gmsg<ISOGM_PEER_STREAM_OPTIONS>, ck, so, sosz); m->send_to_main_thread(); } break; case HQ_VIDEO: { ASSERT( r.sz < 0, "HQ_VIDEO must be xchg buffer" ); spinlock::auto_simple_lock l(lbsync); locked_bufs.add((data_header_s *)r.d); l.unlock(); incoming_video_frame_s *f = (incoming_video_frame_s *)(r.d + sizeof(data_header_s)); TSNEW( video_frame_decoder_c, this, f ); // not memory leak! } break; case AQ_CONTROL_FILE: { gmsg<ISOGM_FILE> *m = TSNEW(gmsg<ISOGM_FILE>); m->utag = r.get<uint64>(); m->fctl = (file_control_e)r.get<int>(); m->send_to_main_thread(); } break; case HQ_INCOMING_FILE: { gmsg<ISOGM_FILE> *m = TSNEW(gmsg<ISOGM_FILE>); m->sender.protoid = id; m->sender.contactid = r.get<int>(); m->utag = r.get<uint64>(); m->filesize = r.get<uint64>(); m->filename.set_as_utf8(r.getastr()); m->send_to_main_thread(); } break; case HQ_QUERY_FILE_PORTION: { gmsg<ISOGM_FILE> *m = TSNEW(gmsg<ISOGM_FILE>); m->utag = r.get<uint64>(); m->offset = r.get<uint64>(); m->filesize = r.get<int>(); m->send_to_main_thread(); } break; case HQ_FILE_PORTION: { gmsg<ISOGM_FILE> *m = TSNEW(gmsg<ISOGM_FILE>); m->utag = r.get<uint64>(); m->offset = r.get<uint64>(); int dsz; const void *data = r.get_data(dsz); m->data.set_size(dsz); memcpy(m->data.data(), data, dsz); m->send_to_main_thread(); } break; case HQ_AVATAR_DATA: { gmsg<ISOGM_AVATAR> *m = TSNEW(gmsg<ISOGM_AVATAR>); m->contact.protoid = id; m->contact.contactid = r.get<int>(); m->tag = r.get<int>(); int dsz; const void *data = r.get_data(dsz); m->data.set_size(dsz); memcpy(m->data.data(), data, dsz); m->send_to_main_thread(); } break; case HQ_EXPORT_DATA: { int dsz; const void *data = r.get_data(dsz); gmsg<ISOGM_EXPORT_PROTO_DATA> *m = TSNEW(gmsg<ISOGM_EXPORT_PROTO_DATA>, id); m->buf.set_size(dsz); memcpy(m->buf.data(), data, dsz); m->send_to_main_thread(); } break; case HQ_TYPING: { gmsg<ISOGM_TYPING> *m = TSNEW(gmsg<ISOGM_TYPING>); int gid = r.get<int>(); contact_key_s ck; m->contact.protoid = id | (gid << 16); // assume 65536 unique groups max m->contact.contactid = r.get<int>(); m->send_to_main_thread(); } break; } return true; }
void device::data_talk(int secondary_address) { DMSG("> iec_data_talk"); secondary_command( CMD_DATA(secondary_address), true ); DMSG("< iec_data_talk"); }
Object *parseFile(FILE *file, Object *parent) { /* State: 0 = read tag name [ ] 1 = wait for property list [(] 2 = check new objects [(] 3 = Read content if tag name is code */ int state = 0; int c; char **propertyList; char *name = MALLOCN(char, 255); int i = 0; int iChild = 0; Object **childs; childs = MALLOCN(Object *, 255); Object *obj; DMSG("parse file\n"); for (c = fgetc(file); c != ')'; c = fgetc(file)) { switch (state) { case 0: switch (c) { case ' ': name[i] = '\0'; state = 1; DMSG("switch to state 1\n"); break; default: name[i++] = c; break; } break; case 1: switch (c) { case '(': propertyList = parseProperties(name, file); obj = createObject(name, propertyList); if (strcmp(name, "code") == 0) { state = 3; DMSG("switch to state 3\n"); } else { state = 2; DMSG("switch to state 2\n"); } break; } break; case 2: switch (c) { case '(': childs[iChild++] = parseFile(file, obj); childs[iChild] = NULL; break; } break; case 3: DMSG("Got code - search vor (\n"); switch (c) { case '(': DMSG("Found\n"); parseCode(file, obj, propertyList); state = 2; break; } break; } } DMSG("Set parent and childs\n"); obj->parent = parent; obj->childs = childs; DMSG("Insert into Global index\n"); insertGlobalIndex(obj); if (obj->onInit != NULL) execEvent(obj->onInit, obj); DMSG("parsing finished\n"); return obj; }
static int sql_fs_ftruncate_internal(TEE_Result *errno, int fd, tee_fs_off_t new_length) { struct sql_fs_fd *fdp; tee_fs_off_t old_length; int rc = -1; DMSG("(fd: %d, new_length: %" PRId64 ")...", fd, new_length); *errno = TEE_ERROR_GENERIC; fdp = handle_lookup(&fs_db, fd); if (!fdp) { *errno = TEE_ERROR_BAD_PARAMETERS; goto exit_ret; } old_length = (tee_fs_off_t)fdp->meta.length; if (new_length == old_length) { rc = 0; goto exit_ret; } sql_fs_begin_transaction_rpc(); if (new_length < old_length) { /* Trim unused blocks */ int old_last_block = block_num(old_length); int last_block = block_num(new_length); tee_fs_off_t off; if (last_block < old_last_block) { off = block_pos_raw(last_block); rc = tee_fs_rpc_ftruncate(OPTEE_MSG_RPC_CMD_SQL_FS, fd, off); if (rc < 0) goto exit; } } else { /* Extend file with zeroes */ tee_fs_off_t off = old_length % BLOCK_SIZE; size_t bnum = block_num(old_length); size_t end_bnum = block_num(new_length); while (bnum <= end_bnum) { size_t len = (size_t)BLOCK_SIZE - (size_t)off; rc = write_block_partial(errno, fdp, bnum, NULL, len, off); if (rc < 0) goto exit; off = 0; bnum++; } } fdp->meta.length = new_length; rc = write_meta(errno, fdp); exit: sql_fs_end_transaction_rpc(rc < 0); exit_ret: DMSG("...%d", rc); return rc; }
static TEE_Result create_ta(void) { DMSG("create entry point for static ta \"%s\"", TA_NAME); return TEE_SUCCESS; }
static int sql_fs_read(TEE_Result *errno, int fd, void *buf, size_t len) { struct sql_fs_fd *fdp; size_t remain_bytes = len; uint8_t *data_ptr = buf; uint8_t *block = NULL; int start_block_num; int end_block_num; int res = -1; int ret; DMSG("(fd: %d, buf: %p, len: %zu)...", fd, (void *)buf, len); mutex_lock(&sql_fs_mutex); *errno = TEE_ERROR_GENERIC; fdp = handle_lookup(&fs_db, fd); if (!fdp) { *errno = TEE_ERROR_BAD_PARAMETERS; goto exit_ret; } if ((fdp->pos + len) < len || fdp->pos > (tee_fs_off_t)fdp->meta.length) len = 0; else if (fdp->pos + len > fdp->meta.length) len = fdp->meta.length - fdp->pos; if (!len) { res = 0; goto exit_ret; } if (!buf) { *errno = TEE_ERROR_BAD_PARAMETERS; goto exit_ret; } if (fdp->flags & TEE_FS_O_WRONLY) { *errno = TEE_ERROR_ACCESS_CONFLICT; goto exit_ret; } start_block_num = block_num(fdp->pos); end_block_num = block_num(fdp->pos + len - 1); block = malloc(BLOCK_SIZE); if (!block) { *errno = TEE_ERROR_OUT_OF_MEMORY; goto exit_ret; } sql_fs_begin_transaction_rpc(); while (start_block_num <= end_block_num) { tee_fs_off_t offset = fdp->pos % BLOCK_SIZE; size_t size_to_read = MIN(remain_bytes, (size_t)BLOCK_SIZE); if (size_to_read + offset > BLOCK_SIZE) size_to_read = BLOCK_SIZE - offset; /* * REVISIT: implement read_block_partial() since we have * write_block_partial()? */ res = read_block(errno, fdp, start_block_num, block); if (res < 0) goto exit; memcpy(data_ptr, block + offset, size_to_read); data_ptr += size_to_read; remain_bytes -= size_to_read; fdp->pos += size_to_read; start_block_num++; } res = 0; exit: sql_fs_end_transaction_rpc(res < 0); free(block); exit_ret: mutex_unlock(&sql_fs_mutex); ret = (res < 0) ? res : (int)len; DMSG("...%d", ret); return ret; }
uint32_t tee_svc_sys_nocall(void) { DMSG("No syscall"); return 0x1; }
static int sql_fs_write(TEE_Result *errno, int fd, const void *buf, size_t len) { struct sql_fs_fd *fdp; size_t remain_bytes = len; const uint8_t *data_ptr = buf; int start_block_num; int end_block_num; int res = -1; int ret; DMSG("(fd: %d, buf: %p, len: %zu)...", fd, (void *)buf, len); mutex_lock(&sql_fs_mutex); *errno = TEE_ERROR_GENERIC; fdp = handle_lookup(&fs_db, fd); if (!fdp) { *errno = TEE_ERROR_BAD_PARAMETERS; goto exit_ret; } if (!len) { res = 0; goto exit_ret; } if (!buf) { *errno = TEE_ERROR_BAD_PARAMETERS; goto exit_ret; } if (fdp->flags & TEE_FS_O_RDONLY) { *errno = TEE_ERROR_ACCESS_CONFLICT; goto exit_ret; } sql_fs_begin_transaction_rpc(); if (fdp->meta.length < (size_t)fdp->pos) { /* Fill hole */ res = sql_fs_ftruncate_internal(errno, fd, fdp->pos); if (res < 0) goto exit; } start_block_num = block_num(fdp->pos); end_block_num = block_num(fdp->pos + len - 1); while (start_block_num <= end_block_num) { tee_fs_off_t offset = fdp->pos % BLOCK_SIZE; size_t size_to_write = MIN(remain_bytes, (size_t)BLOCK_SIZE); if (size_to_write + offset > BLOCK_SIZE) size_to_write = BLOCK_SIZE - offset; res = write_block_partial(errno, fdp, start_block_num, data_ptr, size_to_write, offset); if (res < 0) goto exit; data_ptr += size_to_write; remain_bytes -= size_to_write; fdp->pos += size_to_write; start_block_num++; } fdp->meta.length = fdp->pos; res = write_meta(errno, fdp); exit: sql_fs_end_transaction_rpc(res < 0); exit_ret: mutex_unlock(&sql_fs_mutex); ret = (res < 0) ? res : (int)len; DMSG("...%d", ret); return ret; }
uint32_t tee_svc_sys_dummy(uint32_t *a) { DMSG("tee_svc_sys_dummy: a 0x%x", (unsigned int)a); return 0; }
int minizip_unpack_to_disk(char *path, void *ptr, int len) { // check the magic char *data = (char*)ptr; if (data[0]!='P'||data[1]!='K') goto unpack_to_disk_fail; // setup the memory image zlib_filefunc_def pzlib_filefunc_def; fill_memory_filefunc(&pzlib_filefunc_def); char memname[128]; sprintf(memname,"%lx+%lx", (unsigned long)ptr, (unsigned long)len); unzFile hFile = unzOpen2(memname,&pzlib_filefunc_def); // get info unz_global_info globalInfo = {0}; if (!unzGetGlobalInfo(hFile, &globalInfo )==UNZ_OK ) goto unpack_to_disk_fail; int entries = globalInfo.number_entry; // do the unpacking if (unzGoToFirstFile(hFile) != UNZ_OK) goto unpack_to_disk_fail; int i=0; while (1) { char fname[1024]; char filename_inzip[256]={0}; unz_file_info64 file_info; if (unzGetCurrentFileInfo64(hFile,&file_info, filename_inzip,sizeof(filename_inzip), NULL,0,NULL,0)!=UNZ_OK) goto unpack_to_disk_fail; sprintf(fname,"%s%c%s", path, #ifdef WIN32 '\\' #else '/' #endif , filename_inzip); int fname_len = strlen(filename_inzip); if (filename_inzip[fname_len-1]=='/'||filename_inzip[fname_len-1]=='\\') { // it's a directory _minizip_mkdir(fname); } else { // it's a file if (unzOpenCurrentFile(hFile) != UNZ_OK) goto unpack_to_disk_fail; FILE *fd =0; int n_tot=0, n_read=0; unsigned char buf[32768]; while ((n_read = unzReadCurrentFile(hFile, buf, 32768)) > 0) { if (!n_tot&&!fd&&!_minizip_file_exists(fname)) { DMSG("fopen %s", fname); fd = fopen(fname,"wb"); } if (fd) { DMSG("fwrite %i", n_read); fwrite(buf,n_read,1,fd); } n_tot+=n_read; } if (fd) { DMSG("fclose"); fclose(fd); } DMSG("%s [%i]",fname,n_tot); unzCloseCurrentFile(hFile); } if (++i==entries) break; if (unzGoToNextFile(hFile)!=UNZ_OK) goto unpack_to_disk_fail; } // cleanup unzClose(hFile); return 0; unpack_to_disk_fail: return 1; }
static void pcsc_reader_dump(struct pcsc_reader *r) { DMSG("[%s]:", r->se_reader.name); if (r->state & PCSC_READER_STATE_IGNORE) DMSG(" Ignore this reader"); if (r->state & PCSC_READER_STATE_UNKNOWN) DMSG(" Reader unknown"); if (r->state & PCSC_READER_STATE_UNAVAILABLE) DMSG(" Status unavailable"); if (r->state & PCSC_READER_STATE_EMPTY) DMSG(" Card removed"); if (r->state & PCSC_READER_STATE_PRESENT) DMSG(" Card inserted"); if (r->state & PCSC_READER_STATE_ATRMATCH) DMSG(" ATR matches card"); if (r->state & PCSC_READER_STATE_EXCLUSIVE) DMSG(" Exclusive Mode"); if (r->state & PCSC_READER_STATE_INUSE) DMSG(" Shared Mode"); if (r->state & PCSC_READER_STATE_MUTE) DMSG(" Unresponsive card"); if (r->state & PCSC_READER_STATE_UNPOWERED) DMSG(" Reader Unpowered,"); if (r->state & PCSC_READER_STATE_PRESENT) DMSG("Card Connected: [%s]", r->connected ? "Yes" : "No"); if (r->connected) { char dumpbuf[DUMP_BUF_MAX], *buf = dumpbuf; size_t remain = DUMP_BUF_MAX; buf = print_buf(buf, &remain, "ATR: "); dump_hex(buf, &remain, r->atr, r->atr_len); DMSG("%s", buf); } }
static void *dso_thread(void *ptr) { DMSG("DSO thread started\n"); while(!fl_terminate) { if(!fl_running) { pthread_mutex_lock(&thread_mutex); // wait on signal pthread_mutex_unlock(&thread_mutex); if(fl_terminate) return 0; } //DMSG("period = %d\n", dso_period_usec); if(my_cb) { my_cb(); my_cb = 0; } dso_capture_start(); myusleep(dso_period_usec); dso_trigger_enabled(); int fl_complete = 0; int trPoint = 0; int nr_empty = 0; while(!fl_complete) { int cs = dso_get_capture_state(&trPoint); if (cs < 0) { DMSG("dso_get_capture_state io error\n"); continue; } switch(cs) { case 0: // empty if(nr_empty == 3) { dso_capture_start(); nr_empty = 0; } nr_empty++; dso_trigger_enabled(); dso_force_trigger(); myusleep(dso_period_usec); break; case 1: // in progress myusleep(dso_period_usec >> 1); myusleep(dso_period_usec >> 1); break; case 2: // full pthread_mutex_lock(&buffer_mutex); if (dso_get_channel_data(dso_buffer, dso_buffer_size) < 0) { DMSG("Error in command GetChannelData\n"); } dso_buffer_dirty = 1; dso_trigger_point = trPoint; pthread_mutex_unlock(&buffer_mutex); /*FORMERLEY UPDATE_GUI */ fl_complete = 1; break; default: DMSG("unknown capture state %i\n", cs); break; } } } return 0; }
/* * Called when the instance of the TA is destroyed if the TA has not * crashed or panicked. This is the last call in the TA. */ void TA_DestroyEntryPoint(void) { DMSG("has been called"); }
static int __devinit ist30xx_probe(struct i2c_client * client, const struct i2c_device_id * id) { int ret; struct ist30xx_data *data; struct input_dev *input_dev; #if 0 /* [email protected] */ struct touch_platform_data *ts_pdata; // struct ist30xx_ts_device *dev; ts_pdata = client->dev.platform_data; // dev = &ist30xx_ts_dev; /* [email protected] */ #endif tsp_info("\n%s(), the i2c addr=0x%x \n", __func__, client->addr); /* dev->power = ts_pdata->power; dev->num_irq = ts_pdata->irq; dev->sda_gpio = ts_pdata->sda; dev->scl_gpio = ts_pdata->scl;*/ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { tsp_debug("failed to i2c functionality check"); ret = -ENODEV; goto err_check_functionality_failed; } data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; if(client->dev.of_node) { data->pdata = devm_kzalloc(&client->dev, sizeof(struct ist30xx_tsi_platform_data), GFP_KERNEL); if(!data->pdata) { tsp_debug("failed to allocate platform_data"); return -ENOMEM; } ret = ist30xx_parse_dt(&client->dev, data->pdata); if(ret) { tsp_debug("device tree parsing failed"); return ret; } } else { data->pdata = client->dev.platform_data; } ret = ist30xx_regulator_configure(data, true); if (ret < 0) { tsp_debug("Failed to configure regulators"); } ret = ist30xx_ldo_power_on(data, true); if (ret < 0) { tsp_debug("Failed to power on"); } input_dev = input_allocate_device(); if (!input_dev) { ret = -ENOMEM; tsp_err("%s(), input_allocate_device failed (%d)\n", __func__, ret); goto err_alloc_dev; } #if 0 DMSG("[ TSP ] irq : %d, scl : %d, sda : %d\n", client->irq, ts_pdata->scl, ts_pdata->sda); #endif data->num_fingers = IST30XX_MAX_MT_FINGERS; data->num_keys = IST30XX_MAX_MT_FINGERS; data->irq_enabled = 1; data->client = client; data->input_dev = input_dev; #if 0 /* [email protected] */ data->power = ts_pdata->power; /* [email protected] */ #endif i2c_set_clientdata(client, data); #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 0, 0)) input_mt_init_slots(input_dev, IST30XX_MAX_MT_FINGERS); #endif input_dev->name = "ist30xx_ts_input"; input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; set_bit(EV_ABS, input_dev->evbit); #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 0, 0)) set_bit(INPUT_PROP_DIRECT, input_dev->propbit); #endif input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, IST30XX_MAX_X, 0, 0); input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, IST30XX_MAX_Y, 0, 0); #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 0, 0)) input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, IST30XX_MAX_W, 0, 0); #else input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, IST30XX_MAX_Z, 0, 0); input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, IST30XX_MAX_W, 0, 0); #endif #if IST30XX_USE_KEY { int i; set_bit(EV_KEY, input_dev->evbit); set_bit(EV_SYN, input_dev->evbit); for (i = 1; i < ARRAY_SIZE(ist30xx_key_code); i++) set_bit(ist30xx_key_code[i], input_dev->keybit); } #endif input_set_drvdata(input_dev, data); ret = input_register_device(input_dev); if (ret) { input_free_device(input_dev); goto err_reg_dev; } #if defined(CONFIG_FB) data->fb_notif.notifier_call = fb_notifier_callback; ret = fb_register_client(&data->fb_notif); if(ret) tsp_debug("Unable to register fb_notifier \n"); else tsp_debug("Register fb_notifier \n"); #elif defined(CONFIG_HAS_EARLYSUSPEND) data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; data->early_suspend.suspend = ist30xx_early_suspend; data->early_suspend.resume = ist30xx_late_resume; register_early_suspend(&data->early_suspend); #endif ts_data = data; ret = ist30xx_init_system(); if (ret) { dev_err(&client->dev, "chip initialization failed\n"); goto err_init_drv; } ret = ist30xx_init_update_sysfs(); if (ret) goto err_init_drv; #if IST30XX_DEBUG ret = ist30xx_init_misc_sysfs(); if (ret) goto err_init_drv; #endif # if IST30XX_FACTORY_TEST ret = ist30xx_init_factory_sysfs(); if (ret) goto err_init_drv; #endif #if IST30XX_TRACKING_MODE ret = ist30xx_init_tracking_sysfs(); if (ret) goto err_init_drv; #endif ret = request_threaded_irq(client->irq, NULL, ist30xx_irq_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "ist30xx_ts", data); if (ret) goto err_irq; ist30xx_disable_irq(data); #if IST30XX_INTERNAL_BIN # if IST30XX_UPDATE_BY_WORKQUEUE INIT_DELAYED_WORK(&work_fw_update, fw_update_func); schedule_delayed_work(&work_fw_update, IST30XX_UPDATE_DELAY); # else ret = ist30xx_auto_bin_update(data); if (ret < 0) goto err_irq; # endif #endif // IST30XX_INTERNAL_BIN ret = ist30xx_get_info(data); tsp_info("Get info: %s\n", (ret == 0 ? "success" : "fail")); INIT_DELAYED_WORK(&work_reset_check, reset_work_func); #if IRQ_THREAD_WORK_QUEUE INIT_WORK(&work_irq_thread, irq_thread_func); #endif #if IST30XX_DETECT_TA ist30xx_ta_status = 0; #endif #if IST30XX_EVENT_MODE init_timer(&idle_timer); idle_timer.function = timer_handler; idle_timer.expires = jiffies_64 + (EVENT_TIMER_INTERVAL); mod_timer(&idle_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL); ktime_get_ts(&t_event); #endif ist30xx_initialized = 1; return 0; err_irq: ist30xx_disable_irq(data); free_irq(client->irq, data); err_init_drv: #if IST30XX_EVENT_MODE get_event_mode = false; #endif tsp_err("Error, ist30xx init driver\n"); // ist30xx_power_off(); ist30xx_ts_off(); input_unregister_device(input_dev); return 0; err_reg_dev: err_alloc_dev: tsp_err("Error, ist30xx mem free\n"); kfree(data); err_check_functionality_failed: return 0; }
static void init_runtime(unsigned long pageable_part) { size_t n; size_t init_size = (size_t)__init_size; size_t pageable_size = __pageable_end - __pageable_start; size_t hash_size = (pageable_size / SMALL_PAGE_SIZE) * TEE_SHA256_HASH_SIZE; tee_mm_entry_t *mm; uint8_t *paged_store; uint8_t *hashes; assert(pageable_size % SMALL_PAGE_SIZE == 0); assert(hash_size == (size_t)__tmp_hashes_size); /* * This needs to be initialized early to support address lookup * in MEM_AREA_TEE_RAM */ tee_pager_early_init(); thread_init_boot_thread(); init_asan(); malloc_add_pool(__heap1_start, __heap1_end - __heap1_start); malloc_add_pool(__heap2_start, __heap2_end - __heap2_start); hashes = malloc(hash_size); IMSG_RAW("\n"); IMSG("Pager is enabled. Hashes: %zu bytes", hash_size); assert(hashes); asan_memcpy_unchecked(hashes, __tmp_hashes_start, hash_size); /* * Need tee_mm_sec_ddr initialized to be able to allocate secure * DDR below. */ teecore_init_ta_ram(); carve_out_asan_mem(&tee_mm_sec_ddr); mm = tee_mm_alloc(&tee_mm_sec_ddr, pageable_size); assert(mm); paged_store = phys_to_virt(tee_mm_get_smem(mm), MEM_AREA_TA_RAM); /* * Load pageable part in the dedicated allocated area: * - Move pageable non-init part into pageable area. Note bootloader * may have loaded it anywhere in TA RAM hence use memmove(). * - Copy pageable init part from current location into pageable area. */ memmove(paged_store + init_size, phys_to_virt(pageable_part, core_mmu_get_type_by_pa(pageable_part)), __pageable_part_end - __pageable_part_start); asan_memcpy_unchecked(paged_store, __init_start, init_size); /* Check that hashes of what's in pageable area is OK */ DMSG("Checking hashes of pageable area"); for (n = 0; (n * SMALL_PAGE_SIZE) < pageable_size; n++) { const uint8_t *hash = hashes + n * TEE_SHA256_HASH_SIZE; const uint8_t *page = paged_store + n * SMALL_PAGE_SIZE; TEE_Result res; DMSG("hash pg_idx %zu hash %p page %p", n, hash, page); res = hash_sha256_check(hash, page, SMALL_PAGE_SIZE); if (res != TEE_SUCCESS) { EMSG("Hash failed for page %zu at %p: res 0x%x", n, page, res); panic(); } } /* * Assert prepaged init sections are page aligned so that nothing * trails uninited at the end of the premapped init area. */ assert(!(init_size & SMALL_PAGE_MASK)); /* * Initialize the virtual memory pool used for main_mmu_l2_ttb which * is supplied to tee_pager_init() below. */ init_vcore(&tee_mm_vcore); /* * Assign alias area for pager end of the small page block the rest * of the binary is loaded into. We're taking more than needed, but * we're guaranteed to not need more than the physical amount of * TZSRAM. */ mm = tee_mm_alloc2(&tee_mm_vcore, (vaddr_t)tee_mm_vcore.hi - TZSRAM_SIZE, TZSRAM_SIZE); assert(mm); tee_pager_set_alias_area(mm); /* * Claim virtual memory which isn't paged. * Linear memory (flat map core memory) ends there. */ mm = tee_mm_alloc2(&tee_mm_vcore, VCORE_UNPG_RX_PA, (vaddr_t)(__pageable_start - VCORE_UNPG_RX_PA)); assert(mm); /* * Allocate virtual memory for the pageable area and let the pager * take charge of all the pages already assigned to that memory. */ mm = tee_mm_alloc2(&tee_mm_vcore, (vaddr_t)__pageable_start, pageable_size); assert(mm); tee_pager_add_core_area(tee_mm_get_smem(mm), tee_mm_get_bytes(mm), TEE_MATTR_PRX, paged_store, hashes); tee_pager_add_pages((vaddr_t)__pageable_start, init_size / SMALL_PAGE_SIZE, false); tee_pager_add_pages((vaddr_t)__pageable_start + init_size, (pageable_size - init_size) / SMALL_PAGE_SIZE, true); /* * There may be physical pages in TZSRAM before the core load address. * These pages can be added to the physical pages pool of the pager. * This setup may happen when a the secure bootloader runs in TZRAM * and its memory can be reused by OP-TEE once boot stages complete. */ tee_pager_add_pages(tee_mm_vcore.lo, (VCORE_UNPG_RX_PA - tee_mm_vcore.lo) / SMALL_PAGE_SIZE, true); }
/* parsing lists {{{*/ if(service) { xmlNodePtr memberships = findNode(service->children, "Memberships", 1); xmlNodePtr ms; xmlNodePtr role; xmlNodePtr members, member; xmlNodePtr pname; xmlNodePtr type; xmlNodePtr lastchange; xmlChar *content; int flag = 0; lastchange = findNode(service->children, "LastChange", 1); content = xmlNodeGetContent(lastchange); cl->lastchange = strdup((char*)content); DMSG(stderr, "Contact: lastchange = %s\n", cl->lastchange); if(!memberships) { fprintf(stderr, "NULL membership\n"); count = 0; goto cleanup; } for(ms=memberships->children;ms;ms=ms->next) { int ctype = 1; if(!ms->children) continue; role = findNode(ms->children, "MemberRole", 1); if(!role) { fprintf(stderr, "Null role\n"); count = 0; goto cleanup; } members = findNode(role, "Members", 1); if(!members) continue; if(xmlStrEqual(role->children->content, (xmlChar*)"Allow")) flag = 3; else if(xmlStrEqual(role->children->content, (xmlChar*)"Block")) flag = 4; else continue; for(member=members->children;member;member=member->next) { Contact *c; type = findNode(member->children, "Type", 1); content = xmlNodeGetContent(type); if(!content) { fprintf(stderr, "NULL Type\n"); continue; } if(xmlStrEqual(content, (xmlChar*)"Passport")) { pname = findNode(member->children, "PassportName", 1); ctype = 1; } else if(xmlStrEqual(content, (xmlChar*)"Email")) { pname = findNode(member->children, "Email", 1); ctype = 32; } else continue; xmlFree(content); if(!pname) { fprintf(stderr, "NULL PassportName or Email\n"); continue; } content = xmlNodeGetContent(pname); if(content) { char name[32]; char domain[32]; if(sscanf((char*)content, "%[^@]@%s", name, domain) != 2) { fprintf(stderr, "parse contact: malformed email: %s\n", content); continue; } c = contact_new((char*)content); c->name = strdup(name); c->type = ctype; c->status = NA; c->inlist |= flag; c->domain = NULL; /* should be filled during sort */ cl_append_contact(cl, c, name, domain); xmlFree(content); count++; } } } }/*}}}*/ DMSG(stderr, "parsed contact count: %d\n", count); cleanup: cl->flag &= ~CL_INITLIST; return count; }/*}}}*/ int _cl_do_soapreq_ab(CL *cl)/*{{{*/ { TCPClient *client; char *req = NULL; char *header; char buf[512]; int ret, len; char *ptr = NULL; client = tcpclient_new("contacts.msn.com", 80); ret = _cl_load_soapreq_ab(cl, cl->ablastchange, &req, TRUE); if(ret) { tcpclient_connect(client); header = (char*)xmalloc(strlen(ab_request_header) + 32); DMSG(stderr, "sending ab request\n"); len = sprintf(header, "%s%d\r\n\r\n", ab_request_header, ret); if(tcpclient_send(client, header, len) <= 0) goto cleanup; if(tcpclient_send(client, req, ret) <= 0) goto cleanup; len = tcpclient_recv_header(client, &ptr); /* header */ if(ptr) { HTTPHeader *header; xmlDocPtr doc; xmlParserCtxtPtr ctxt; FILE *fp; DMSG(stderr, "AB response header:\n%s", ptr); header = http_parse_header(ptr); len = header->content_length; DMSG(stderr, "Length: %d\n", len); http_header_destroy(header); memset(buf, 0, sizeof(buf)); fp = fopen("addressbook.xml", "w"); fprintf(fp, buf); len -= (ret = tcpclient_recv(client, buf, sizeof(buf)-1)); ctxt = xmlCreatePushParserCtxt(NULL, NULL, buf, ret, "addressbook.xml"); fprintf(fp, buf); if(ctxt == NULL) { fprintf(stderr, "failed to create parser context"); return 0; } while(len > 0) { memset(buf, 0, sizeof(buf)); len -= (ret=tcpclient_recv(client, buf, sizeof(buf)-1)); fprintf(fp, buf); xmlParseChunk(ctxt, buf, ret, 0); } fclose(fp); xmlParseChunk(ctxt, buf, 0, 1); tcpclient_destroy(client); client = NULL; doc = ctxt->myDoc; len = ctxt->wellFormed; xmlFreeParserCtxt(ctxt); //count += _cl_parse_contacts(cl, doc); xmlFreeDoc(doc); xmlCleanupParser(); DMSG(stderr, "addressbook xml parsing done: %s\n", len?"good":"malformed"); xfree(ptr); } else { DMSG(stderr, "ab: no header found\n\r"); } } else { fprintf(stderr, "failed to load abreq\n"); } cleanup: xfree(header); return 0; }/*}}}*/