/****************************************************************************** * * Copyright (C) 2020-2021 Rockchip Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef LOG_TAG #define LOG_TAG "zdm" #endif #define HCI_GRP_LINK_CONTROL_CMDS (0x01 << 10) /* 0x0400 */ #define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */ /* Commands of HCI_GRP_HOST_CONT_BASEBAND_CMDS */ #define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* Commands of HCI_GRP_LINK_CONTROL_CMDS group */ #define HCI_Change_Connection_Packet_Type (0x000F | HCI_GRP_LINK_CONTROL_CMDS) #define HCIC_PARAM_SIZE_CHANGE_CONN_TYPE 4 #define HCIC_HEADER_SIZE 3//opcode(2)+paralen(1) /* Command opcode pack/unpack */ #define cmd_opcode_pack(ogf, ocf) ((uint16_t)((ocf & 0x03ff)|(ogf << 10))) #define MAXSLEEP 4 static const int SERV_ADDR = 0x7f000001; static const uint16_t SERV_PORT = 8873; #define BIT(x) (1<>8&0xff;//paralen cmd[3] = opcode&0xff;//opcode cmd[4] = opcode>>8&0xff; cmd[5] = len; //para len total = 3 + HCIC_HEADER_SIZE + cmd[5]; ptr = &cmd[6]; for(i= optind, paralen = 0; i < argc && paralen < (int)sizeof(cmd); i++, paralen++){ *ptr++ = (uint8_t) strtol(argv[optind++], NULL, 16); } LOGD("paralen:%d , len =%d, %s\n", paralen, len, (paralen == len)?"ok":"some error!"); LOGD("hci command:%02x (%02x %02x)", cmd[0], cmd[1], cmd[2]); for(int i = 0; i < len+3; i++){ printf(" %02x", cmd[3+i]); } printf("\n"); } else{ //printf("optind:%d argc:%d", optind, argc); while (optind < argc) { const char *opt = argv[optind]; printf("%s ", opt); if(findBrEdrType(opt, &inverse, &bitmask)){ if(inverse) airType&=~bitmask; else airType|=bitmask; } optind++; } } LOGD("\n final airType :0x%04x, handle=0x%02x\n", airType, handle); if(hcicmd){ #if 0 cmd[0] = 0x01;//cmd cmd[1] = (HCIC_HEADER_SIZE+0)&0xff;//len cmd[2] = (HCIC_HEADER_SIZE+0)>>8&0xff; cmd[3] = HCI_RESET&0xff;//opcode cmd[4] = HCI_RESET>>8&0xff; cmd[5] = 0; //para total = 3 + HCIC_HEADER_SIZE; #endif if (write(fd, cmd, total) != total) { fprintf(stderr, "Failed to write reset command\n"); goto MAIN_EXIT; } } else{ cmd[0] = 0x01;//cmd cmd[1] = (HCIC_HEADER_SIZE+HCIC_PARAM_SIZE_CHANGE_CONN_TYPE)&0xff;//len cmd[2] = (HCIC_HEADER_SIZE+HCIC_PARAM_SIZE_CHANGE_CONN_TYPE)>>8&0xff; cmd[3] = HCI_Change_Connection_Packet_Type&0xff;//opcode cmd[4] = HCI_Change_Connection_Packet_Type>>8&0xff; cmd[5] = HCIC_PARAM_SIZE_CHANGE_CONN_TYPE;//opcode cmd[6] = handle&0xff;//opcode cmd[7] = handle>>8&0xff; cmd[8] = airType&0xff;//opcode cmd[9] = airType>>8&0xff; total = 3 + HCIC_HEADER_SIZE + HCIC_PARAM_SIZE_CHANGE_CONN_TYPE; if (write(fd, cmd, total) != total) { fprintf(stderr, "Failed to write reset command\n"); goto MAIN_EXIT; } } //while(1); //usage(); close(fd); LOGD("exit successful!!!\n"); //usage(); exit(0);//return 0; MAIN_EXIT: close(fd); LOGD("exit unsuccessful!!!\n"); //usage(); exit(1); }