From: Mattias A. <mat...@us...> - 2001-08-22 17:46:38
|
The following file was modified in apps/bluetooth/sdp_server: Name Old version New version Comment ---- ----------- ----------- ------- sdp_server.c 1.29 1.30=20=20=20=20=20=20=20=20=20=20=20=20 The accompanying log: * fixed bug when handling MaximumServiceRecordCount in service search * changed some debug printouts * corrected spelling * added comments The diff of the modified file(s): --- sdp_server.c 2001/06/19 08:19:37 1.29 +++ sdp_server.c 2001/08/22 17:46:37 1.30 @@ -124,7 +124,7 @@ void set_sdp_hdr(unsigned char *hdr, unsigned char pkt_type, unsigned short trans_id, unsigned short len); =20 -unsigned int* remove_dublicated_rec_hdl(unsigned int *rec_hdl_list_in, +unsigned int* remove_duplicated_rec_hdl(unsigned int *rec_hdl_list_in, unsigned int cnt_in); unsigned int* get_all_rec_hdl(unsigned int *service_class_list, unsigned int service_class_cnt); @@ -276,11 +276,14 @@ int value_string_pos =3D 0; static char tmp_list[256]; char tmp_len =3D 0; - char *des_pos[DES_HDR_DEPTH]; /* des stands for Data Elemet Sequence */ + char *des_pos[DES_HDR_DEPTH]; /* des stands for Data Element Sequence */ int des_len[DES_HDR_DEPTH]; char c_des_len[3][DES_HDR_DEPTH]; int i; =20 + D_MISC(__FUNCTION__" value_string _%s_, valstrlen:%d\n",=20 + value_string, value_string_len); + i =3D 0; while (i < value_string_len) { @@ -299,6 +302,8 @@ /* If we found a hex value instead of a string */ if (strncmp(value_string + value_string_pos, "0x", 2) =3D=3D 0) { + D_MISC("Found HEX val\n"); + strcpy(tmp_list + tmp_len, value_string + value_string_pos + 2); tmp_len +=3D strlen(value_string + value_string_pos) - 2; =20 @@ -314,6 +319,7 @@ =20 /* Now we found a data element sequence header inside another data element sequence */ + if (des_pos[pos]) { sprintf(c_des_len[pos], "%02x", des_len[pos]); @@ -321,8 +327,10 @@ strncpy(des_pos[pos], c_des_len[pos], 2); D_MISC("des_pos[%d]: %s", pos, des_pos[pos]); } + des_pos[pos] =3D tmp_list + tmp_len - 2; des_len[pos] =3D 0; + for (j =3D pos; j > 0; j--) { des_len[0] +=3D (strlen(value_string + value_string_pos) - 2) / = 2; @@ -339,6 +347,9 @@ { char *tmp_code; =20 + D_MISC("Searching xml file : TAG SDPTranslationRegister\n"); + D_MISC("String : _%s_\n", value_string+value_string_pos); +=20=20=20=20=20=20 /* Get the hex code for the attribute from the xml file */ tmp_code =3D get_from_xml(fd, "SDPTranslationRegister", value_string + value_string_pos, NULL); @@ -401,7 +412,7 @@ } =20 unsigned int* -remove_dublicated_rec_hdl(unsigned int *rec_hdl_list_in, unsigned int cnt_= in)=20=20 +remove_duplicated_rec_hdl(unsigned int *rec_hdl_list_in, unsigned int cnt_= in)=20=20 { static unsigned int rec_hdl_list_out[128]; unsigned int i, j, cnt_out =3D 0; @@ -420,7 +431,7 @@ if(!existing) { rec_hdl_list_out[cnt_out] =3D rec_hdl_list_in[i]; - D_RHDL(__FUNCTION__": Found record_handle 0x%08x", rec_hdl_list_out[cnt_o= ut]); + D_RHDL(__FUNCTION__": |||=A0Keeping record_handle 0x%08x |||", rec_hdl_li= st_out[cnt_out]); cnt_out++; } existing =3D FALSE; @@ -439,14 +450,14 @@ unsigned int rec_hdl_cnt =3D 0; int i, j; =20=20=20 - D_RHDL(__FUNCTION__": service_class_cnt:%d", service_class_cnt); + D_RHDL(__FUNCTION__": Searching for %d UUID:s...", service_class_cnt); =20 for (i =3D 0; i < service_class_cnt; i++) { - D_RHDL(__FUNCTION__": Service Class:0x%08x", service_class_list[i]); + D_RHDL(__FUNCTION__": Now search for UUID : 0x%08x", service_class_lis= t[i]); if ((rec_hdl_list[rec_hdl_cnt] =3D get_record_handle(service_class_lis= t[i], xml_fd)) !=3D NO_REC_HDL) { - D_REC("Got Record handle1: 0x%08x", rec_hdl_list[rec_hdl_cnt]); + D_REC("Found record handle : 0x%08x", rec_hdl_list[rec_hdl_cnt]); rec_hdl_cnt++; } =20=20=20=20=20=20=20=20=20 @@ -465,22 +476,30 @@ while (tmp_hdl_list[j] !=3D NO_REC_HDL) { rec_hdl_list[rec_hdl_cnt] =3D tmp_hdl_list[j]; - D_REC("Got Record handle2: 0x%08x", rec_hdl_list[rec_hdl_cnt]); + D_REC("Found record handle : 0x%08x", rec_hdl_list[rec_hdl_cnt]); rec_hdl_cnt++; j++; } =20=20=20=20=20=20=20 + D_RHDL("Found %d record handles using get_more_rec_hdl\n", j); +=20=20=20=20=20=20 D_MEM("<--- free%d 0x%8p", --malloc_dbg, tmp_hdl_list); free(tmp_hdl_list); } =20=20=20=20=20 } =20=20=20 - tmp_hdl_list =3D remove_dublicated_rec_hdl(rec_hdl_list, rec_hdl_cnt); + D_RHDL("Now __remove__ duplicated entries ?!?!?\n"); +=20 + tmp_hdl_list =3D remove_duplicated_rec_hdl(rec_hdl_list, rec_hdl_cnt); =20=20 return tmp_hdl_list; } =20 + +/*=20 + * Searches for "ServiceClasses" entries in database=20 + */ unsigned int get_record_handle(unsigned short service_class, int fd) { @@ -489,11 +508,14 @@ char *service_class_id =3D NULL; char tmp[12]; =20 + D_RHDL("Looking for service class %0x\n", service_class); + /* Before we can get the recordhandle we have to find the name of the service class, so we can search for it in the database. When we search the service class id, have to be converted to characters. All service classes are stored as 16 bits UUIDs*/ =20 + /* Search for UUID as a string among ServiceClasses TAG */ sprintf(tmp, "0x%04x", service_class); service_class_name =3D get_from_xml(fd, "ServiceClasses", NULL, tmp);=20 =20 @@ -504,9 +526,9 @@ return NO_REC_HDL; } =20 - /* Otherwise we got the name for the service class, and we can contiue - searching for the record handle */ + D_RHDL("Found service class name %s\n", service_class_name); =20 + /* We found service class name, now search for record handle */ service_class_id =3D get_from_xml(fd, service_class_name, "ServiceRecordHandle", NULL); =20 @@ -516,9 +538,9 @@ /* If we found the record handle we convert it to an unsigned int */ if (service_class_id !=3D NULL) { - D_RHDL("Found %s", service_class_id); + D_RHDL("Found service_class_id : 0x%x\n", service_class_id); record_handle =3D strtoul(service_class_id, NULL, 16); - D_RHDL("Record handle converted to int 0x%08x", record_handle); + D_RHDL("Service class id conv to rec hdl 0x%08x", record_handle); D_MEM("<--- free%d 0x%8p", --malloc_dbg, service_class_id); free(service_class_id); } @@ -581,6 +603,9 @@ { } =20 +/*=20 + * Searches for Attributes in database=20 + */ unsigned int* get_more_rec_hdl(unsigned short service_class, int fd) { @@ -591,6 +616,9 @@ XML_Parser p; =20 sprintf(tmp_ch, "0x%04x", service_class); + + /* Search for UUID among "Protocols" TAG */ + s_hdl.uuid =3D get_from_xml(fd, "Protocols", NULL, tmp_ch);=20 =20 /* If we didn't find the service class among the protocols we look for it @@ -1351,12 +1379,28 @@ } } =20=20=20 + D_MISC("Found %d rec handles in database\n", rec_hdl_cnt); + + /* Calculate how many records we can fit into response */ + /* SdpHdrSize[5] + TotSrvCnt[2] + CurSrvRevCnt[2] + possibl ContState[2]= =20 + =3D> 11 bytes. Each rec hdl is 4 bytes */ + + max_rec_cnt =3D MIN(db_hdl->max_rec_cnt, (db_hdl->db.l2cap_mtu - 11)/4); + + if (rec_hdl_cnt > max_rec_cnt)=20 + { + D_REC("Only send %d out of %d record handles\n", max_rec_cnt, rec_hdl_= cnt); + rec_hdl_cnt =3D max_rec_cnt; + } +=20=20 rsp_pkt_len =3D SDP_HDR_SIZE;=20=20 =20=20=20 /* Set the total service record count */ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_MS(rec_hdl_cnt); rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_LS(rec_hdl_cnt); =20=20=20 + /* fixme -- total/current should probably differ sometimes... */ +=20=20 /* Set the current service record count */ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_MS(rec_hdl_cnt); rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_LS(rec_hdl_cnt); @@ -1375,11 +1419,19 @@ set_sdp_hdr(rsp_pkt, SDP_SERVICESEARCH_RSP, db_hdl->db.trans_id, rsp_pkt_len - SDP_HDR_SIZE); =20 - max_rec_cnt =3D MIN(db_hdl->max_rec_cnt, db_hdl->db.l2cap_mtu - 11); - /* 11 comes from SDP_HDR_SIZE + tot+cur-rec cnt fiel + 2 bytes for cont + D_REC("l2cap_mtu:%d, mrc:%d, db->mrc:%d\n", db_hdl->db.l2cap_mtu, max_re= c_cnt, db_hdl->max_rec_cnt); + + /* If Max Service Record Count is set to a value less than the number of + available records in database we should not set cont state */ + + /* set_cont_state_search searches rsp_pkt for currently set rec cnt=20 + and we compare that with max_rec_cnt. If current is larger than + max rec cnt, we set continuation state and change headers in rsp + packet. If not we simply put a 0 in the end to indicate no cont=20 state */ =20 - D_REC("l2cap_mtu:%d, mrc:%d, db->mrc:%d\n", db_hdl->db.l2cap_mtu, max_re= c_cnt, db_hdl->max_rec_cnt); + /* fixme -- as of today we can only handle continuation state for=20 + 1 client at a time */ =20=20=20 rsp_pkt_len =3D set_cont_state_search(rsp_pkt, rsp_pkt_len, max_rec_cnt); =20 @@ -1616,8 +1668,10 @@ } else { + D_MISC("No continuation state set\n"); pkt[len++] =3D 0; } +=20=20 =20=20=20 /* Change the length field */ pkt[SDP_HDR_LENGTH_MS] =3D SHORT2CHAR_MS(len - SDP_HDR_SIZE); |