static void dd_context_set_stream_output_targets(struct pipe_context *_pipe, unsigned num_targets, struct pipe_stream_output_target **tgs, const unsigned *offsets) { struct dd_context *dctx = dd_context(_pipe); struct pipe_context *pipe = dctx->pipe; struct dd_draw_state *dstate = &dctx->draw_state; dstate->num_so_targets = num_targets; safe_memcpy(dstate->so_targets, tgs, sizeof(*tgs) * num_targets); safe_memcpy(dstate->so_offsets, offsets, sizeof(*offsets) * num_targets); pipe->set_stream_output_targets(pipe, num_targets, tgs, offsets); }
static int cp_redir_init_client (nw_addr_t * dclient, nw_addr_t * sclient) { safe_memcpy (dclient, sclient, sizeof (nw_addr_t)); CP_ERROR (1, "REDIR client init successful"); return SUCCESS; }
static void dd_context_set_constant_buffer(struct pipe_context *_pipe, enum pipe_shader_type shader, uint index, const struct pipe_constant_buffer *constant_buffer) { struct dd_context *dctx = dd_context(_pipe); struct pipe_context *pipe = dctx->pipe; safe_memcpy(&dctx->draw_state.constant_buffers[shader][index], constant_buffer, sizeof(*constant_buffer)); pipe->set_constant_buffer(pipe, shader, index, constant_buffer); }
static void dd_context_set_vertex_buffers(struct pipe_context *_pipe, unsigned start, unsigned num_buffers, const struct pipe_vertex_buffer *buffers) { struct dd_context *dctx = dd_context(_pipe); struct pipe_context *pipe = dctx->pipe; safe_memcpy(&dctx->draw_state.vertex_buffers[start], buffers, sizeof(buffers[0]) * num_buffers); pipe->set_vertex_buffers(pipe, start, num_buffers, buffers); }
static void dd_context_set_viewport_states(struct pipe_context *_pipe, unsigned start_slot, unsigned num_viewports, const struct pipe_viewport_state *states) { struct dd_context *dctx = dd_context(_pipe); struct pipe_context *pipe = dctx->pipe; safe_memcpy(&dctx->draw_state.viewports[start_slot], states, sizeof(*states) * num_viewports); pipe->set_viewport_states(pipe, start_slot, num_viewports, states); }
static void dd_context_set_shader_images(struct pipe_context *_pipe, enum pipe_shader_type shader, unsigned start, unsigned num, const struct pipe_image_view *views) { struct dd_context *dctx = dd_context(_pipe); struct pipe_context *pipe = dctx->pipe; safe_memcpy(&dctx->draw_state.shader_images[shader][start], views, sizeof(views[0]) * num); pipe->set_shader_images(pipe, shader, start, num, views); }
packet_t *packet_create_msg_chunked(uint16_t session_id, uint32_t chunk) { packet_t *packet = (packet_t*) safe_malloc(sizeof(packet_t)); packet->packet_type = PACKET_TYPE_MSG; packet->packet_id = rand() % 0xFFFF; packet->session_id = session_id; packet->body.msg.options.chunked.chunk = chunk; packet->body.msg.data = safe_memcpy("", 0); packet->body.msg.data_length = 0; return packet; }
packet_t *packet_create_msg_normal(uint16_t session_id, uint16_t seq, uint16_t ack, uint8_t *data, size_t data_length) { packet_t *packet = (packet_t*) safe_malloc(sizeof(packet_t)); packet->packet_type = PACKET_TYPE_MSG; packet->packet_id = rand() % 0xFFFF; packet->session_id = session_id; packet->body.msg.options.normal.seq = seq; packet->body.msg.options.normal.ack = ack; packet->body.msg.data = safe_memcpy(data, data_length); packet->body.msg.data_length = data_length; return packet; }
/**************************************************************************** prompte a dptr (to make it recently used) ****************************************************************************/ void array_promote(char *array,int elsize,int element) { char *p; if (element == 0) return; p = (char *)malloc(elsize); if (!p) { DEBUG(5,("Ahh! Can't malloc\n")); return; } memcpy(p,array + element * elsize, elsize); safe_memcpy(array + elsize,array,elsize*element); memcpy(array,p,elsize); free(p); }
/* --------- FILE COPY -------- */ int unlinkdir(char * dirpath) { int ret, stat; DIR * dp; struct dirent * dirstat; char * filename = (char *)calloc(5, sizeof(char)); ret = 0; stat = 0; if((dp = opendir(dirpath))!=NULL){ for( ;(dirstat = readdir(dp))!=(struct dirent *)NULL; ){ if(0 != self_memcmp(dirstat->d_name, ".")){ if(0 != self_memcmp(dirstat->d_name, "..")){ filename = safe_memcpy(filename, dirpath, BUF_MAX); filename = safe_strncat(filename, "/", BUF_MAX); filename = safe_strncat(filename, dirstat->d_name, BUF_MAX); stat = unlink(filename); if(stat < 0){ fprintf(stderr,"unlinkdir(): not delete file name. <%s>\n", filename); ret = ret - 1; } else{ #ifdef UNLINK_DIR fprintf(stderr,"unlinkdir(): delete file. <%s>\n", filename); #endif } } } } closedir(dp); } else { fprintf(stderr,"unlinkdir(): open dir. <%s>\n", dirpath); ret = -1; } free(filename); return(ret); }
// 文字列全体の中のすべてのchS(char)を、(\r\n)の改行に置き換える。 char * swap_rn(char *data, char chS) { char * swap; int max, count, count1, count2; int nlen = 0; count1 = 0; max = strlen(data); for(count2 = 0; count2 < max; count2++){ if(data[count2] == chS){ nlen++; } } if((swap = (char *)calloc(BUF_DEFLEN, sizeof(char)))==NULL){exit(1);} if(nlen > 0){ if((swap = (char*)realloc(swap, sizeof(char) * (max + nlen + 1)))==NULL){ fprintf(stderr,"swap_rn(): The memory cannot be newly secured. \n"); exit(1); } for(count = 0; count < max; count++){ if(data[count] == chS){ swap[count1] = '\r'; count1++; swap[count1] = '\n'; count1++; } else { swap[count1] = data[count]; count1++; } } swap[count1] = (char)0x00; clean_mem(data, '\0', (int)strlen(data)); data = safe_memcpy(data, swap, BUF_MAX); } free(swap); return data; }
u8 rtl_btcoex_parse_BT_info_notify_cmd(struct rtl_priv *rtlpriv, u8 *pcmd, u16 cmdlen) { u8 curPollEnable = pcmd[0]; u8 curPollTime = pcmd[1]; u8 btInfoReason = pcmd[2]; u8 btInfoLen = pcmd[3]; u8 btinfo[BT_INFO_LENGTH]; RTL_HCI_STATUS status = HCI_STATUS_SUCCESS; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"%s\n",__func__); BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"current Poll Enable: %d, currrent Poll Time: %d\n", curPollEnable,curPollTime); BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"BT Info reason: %d, BT Info length: %d\n", btInfoReason,btInfoLen); BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" ,pcmd[4],pcmd[5],pcmd[6],pcmd[7],pcmd[8],pcmd[9],pcmd[10],pcmd[11]); memset(btinfo, 0, BT_INFO_LENGTH); if(BT_INFO_LENGTH != btInfoLen) { status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_CRITICAL,"Error BT Info Length: %d\n",btInfoLen); } else { if(0x1 == btInfoReason || 0x2 == btInfoReason) { safe_memcpy(btinfo, &pcmd[4], btInfoLen,BT_INFO_LENGTH); btinfo[0] = btInfoReason; rtl_btcoex_btinfo_cmd(rtlpriv,btinfo,btInfoLen); } else { BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"Other BT info reason\n"); } } return rtl_send_complete_event_to_BT(rtlpriv,HCI_BT_INFO_NOTIFY,status); }
// First use reset() to set the internal position to 0. // Then you pass in the buffer where the results go. // You pass in the length of that buffer. // It returns how much was actually read. // If you start at position 0, and read 100 bytes, then // you are now on position 100, and the next OTfread will // proceed from that position. (Unless you reset().) uint32_t OTPassword::OTfread(uint8_t* data, uint32_t size) { OT_ASSERT(data != nullptr && size > 0); uint32_t sizeToRead = 0; if (position_ < size_) { // If the size is 20, and position is 5 (I've already read the first 5 // bytes) then the size remaining to read is 15. That is, GetSize() // minus position_. sizeToRead = size_ - position_; if (size < sizeToRead) { sizeToRead = size; } safe_memcpy(data, sizeToRead, getMemory_uint8(), sizeToRead); position_ += sizeToRead; } return sizeToRead; }
char * mime_ujtoj(char * from) { int i, len, c, kanji_flag, flag; char * head = "=?ISO-2022-jp?B?"; char * tail = "?="; char ato[128]; char * to = ato; char * data = (char *)calloc(2, sizeof(char)); char * swap = (char *)calloc(2, sizeof(char)); memset(to, 0x00, 128); len = (int)strlen(from); c = 0; kanji_flag = 0; flag = 0; for(i = 0; i < len; i++){ if(iseuckanji(from[i])){ // kanji if(kanji_flag == 0){ to[c] = 0x1b; c++; to[c] = 0x24; c++; to[c] = 0x42; c++; kanji_flag = 1; } to[c] = (from[i]&0x7f); c++; to[c] = (from[i+1]&0x7f); c++; i++; #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: kanji %d\n", c); #endif if(c > (76 - 17 * 3 / 4)){ to[c] = 0x1b; c++; to[c] = 0x28; c++; to[c] = 0x4a; c++; to[c] = 0x00; c = 0; swap = safe_memcpy(swap, to, BUF_MAX); #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: kanji <%x> %s \n",swap[0], swap); #endif swap = safe_base64(swap); if(flag == 0){ data = safe_memcpy(data, head, BUF_MAX); } else{ data = safe_strncat(data, "\t ", BUF_MAX); data = safe_strncat(data, head, BUF_MAX); } data = safe_strncat(data, swap, BUF_MAX); data = safe_strncat(data, tail, BUF_MAX); data = safe_strncat(data, "\r\n", BUF_MAX); memset(to, 0x00, 128); flag = 1; kanji_flag = 0; #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: kanji %s\n",data); #endif } } else{ // not kanji if(kanji_flag == 1){ to[c] = 0x1b; c++; to[c] = 0x28; c++; to[c] = 0x4a; c++; kanji_flag = 0; } to[c] = from[i]; c++; #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: not kanji %d\n", c); #endif if(c > (76 - 17 * 3 / 4)){ to[c] = 0x00; c =0; swap = safe_memcpy(swap, to, BUF_MAX); #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: not kanji <%x> %s \n",swap[0], swap); #endif swap = safe_base64(swap); if(flag == 0){ data = safe_memcpy(data, head, BUF_MAX); } else{ data = safe_strncat(data, "\t ", BUF_MAX); data = safe_strncat(data, head, BUF_MAX); } data = safe_strncat(data, swap, BUF_MAX); data = safe_strncat(data, tail, BUF_MAX); data = safe_strncat(data, "\r\n", BUF_MAX); memset(to, 0x00, 128); flag = 1; kanji_flag = 1; #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: not kanji %s\n",data); #endif } } } to[c] = 0x1b; c++; to[c] = 0x28; c++; to[c] = 0x4a; c++; to[c] = '\0'; swap = safe_memcpy(swap, to, BUF_MAX); #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: owari <%x> %s \n",swap[0], swap); #endif swap = safe_base64(swap); if(flag == 0){ data = safe_memcpy(data, head, BUF_MAX); } else{ data = safe_strncat(data, "\t ", BUF_MAX); data = safe_strncat(data, head, BUF_MAX); } data = safe_strncat(data, swap, BUF_MAX); data = safe_strncat(data, tail, BUF_MAX); #ifdef MIME_BASE64_BUG printf("MIME_BASE64_BUG: mime_base64.c: owari %s\n",data); #endif from = safe_memcpy(from, data, BUF_MAX); free(swap); free(data); return from; }
void rtl_btcoex_recvmsg_int(struct sock *sk_in, s32 bytes) { #else void rtl_btcoex_recvmsg_int(struct sock *sk_in) { #endif struct rtl_priv *rtlpriv = pbtcoexadapter; struct bt_coex_info *pcoex_info = &rtlpriv->coex_info; pcoex_info->sk_store = sk_in; queue_delayed_work(pbtcoexadapter->works.rtl_wq, &rtlpriv->works.socket_wq, 0); } void rtl_btcoex_recvmsgbysocket(void* data) { u8 recv_data[RECV_DATA_MAX_LEN]; u32 len = 0; u16 recv_length = 0; u16 parse_res = 0; struct rtl_priv *rtlpriv = pbtcoexadapter; struct bt_coex_info *pcoex_info = &rtlpriv->coex_info; struct sock *sk = pcoex_info->sk_store; struct sk_buff * skb = NULL; if(sk == NULL) BTC_PRINT(BTC_MSG_SOCKET, SOCKET_CRITICAL,"critical error when receive socket data!\n"); len = skb_queue_len(&sk->sk_receive_queue); while(len > 0){ skb = skb_dequeue(&sk->sk_receive_queue); /*important: cut the udp header from skb->data! header length is 8 byte*/ recv_length = skb->len-8; memset(recv_data,0,sizeof(recv_data)); safe_memcpy(recv_data, skb->data+8, recv_length, RECV_DATA_MAX_LEN); /*DBG_871X("received data: %s :with len %u\n",recv_data, skb->len);*/ parse_res = rtl_btcoex_parse_recv_data(recv_data,recv_length); /*DBG_871X("parse_res; %d\n",parse_res);*/ if(RX_ATTEND_ACK == parse_res) //attend ack { pcoex_info ->BT_attend = true; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_ATTEND_ACK!,sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); } if(RX_ATTEND_REQ == parse_res) //attend req from BT { pcoex_info ->BT_attend = true; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_BT_ATTEND_REQ!,sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); rtl_btcoex_sendmsgbysocket(pbtcoexadapter,attend_ack,sizeof(attend_ack),false); } if(RX_INVITE_REQ == parse_res) //attend req from BT { pcoex_info ->BT_attend = true; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_INVITE_REQ!,sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); rtl_btcoex_sendmsgbysocket(pbtcoexadapter,invite_rsp,sizeof(invite_rsp),false); } if(RX_INVITE_RSP == parse_res) //attend req from BT { pcoex_info ->BT_attend = true; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_INVITE_RSP!,sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); } else if (RX_LEAVE_ACK == parse_res) //mean BT know wifi will leave { pcoex_info ->BT_attend = false; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_LEAVE_ACK!,sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); } else if(RX_BT_LEAVE == parse_res) //BT leave { rtl_btcoex_sendmsgbysocket(pbtcoexadapter, leave_ack,sizeof(leave_ack),false); // no ack pcoex_info ->BT_attend = false; BTC_PRINT(BTC_MSG_SOCKET, SOCKET_NORMAL,"RX_BT_LEAVE!sock_open:%d, BT_attend:%d\n",pcoex_info ->sock_open,pcoex_info ->BT_attend); } else/*todo: check if recv data are really hci cmds*/ { if(true == pcoex_info->BT_attend) rtl_btcoex_parse_hci_cmd(pbtcoexadapter,recv_data,recv_length); } len--; kfree_skb(skb); /*never do a sleep in this context!*/ } }