I am trying to send data over BLE from Bluno to a Raspberry Pi (Raspian), bluez 5.50.
Whilst the connection seems to be fine. I am struck in a point where am unable to retrieve serial data from notification handle.
Below is what I tried.
pi#raspberrypi:~ $ sudo gatttool -b <BLE-MAC-ADDRESS> -I
<BLE-MAC-ADDRESS>[LE]> connect
Attempting to connect to <BLE-MAC-ADDRESS>
Connection successful
[<BLE-MAC-ADDRESS>][LE]>
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>char-read-hnd 0x0025
handle : 0x0025 value : 01
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>
So the problem here is , Notification handle listener 'listens' to the serial data and returns the value( 2 -> Hex:32) every 1 second from Bluno (as programmed in Adurinosketch).
But when I try to retrieve this value through the command char-read (tried both by handle & uuid) it always returns 01 ?!!!
Ultimately I want to retrieve this value in my Python code (am using Pexpect for this)
Any help / directions appreciated.
Ok , Here is what I ended up doing in my Python code to retrieve the value
`
child = pexpect.spawn("sudo gatttool -b <BLUNO-MAC-ADDR> -I")
# Connect to the device.
print("Connecting to Bluno...")
child.sendline("connect")
child.expect("Connection successful", timeout=5)
print(" Connected!")
while True:
child.expect("Notification handle = 0x0025 value: ", timeout=10)
child.expect("\r\n", timeout=10)
resp = child.before
print(process_my_data(bytearray.fromhex(resp.decode("utf-8")).decode()))
`
Related
i use readfile to read data from serial port by api instead of WinComm. it works okay but hang on data receive when other side does not sent data, here are some codes:
'----------on port connect section---------------
With cTimeOuts
.ReadIntervalTimeout = 20
.ReadTotalTimeoutMultiplier = 20
.ReadTotalTimeoutConstant = 20
.WriteTotalTimeoutMultiplier = 20
.WriteTotalTimeoutConstant = 20
End With
rtLng = SetCommTimeouts(hPort, cTimeOuts)
'----------on data receive section---------------
With dOverlapped
.Internal = 0
.InternalHigh = 0
.offset = 0
.OffsetHigh = 0
.hEvent = 0
End With
call ReadFile(hPort, BytesBuffer(0), UBound(BytesBuffer) + 1, dwBytesRead, dOverlapped)
i tried:
a. set ReadIntervalTimeout to MAXDWORD and ReadTotalTimeoutMultiplier & ReadTotalTimeoutConstant both to 0, it can avoid hang on receive data, but the receive data will incomplete for random occurred, so this is not my option.
b. some example code on internet using
Call ReadFile(hPort, BytesBuffer(0), UBound(BytesBuffer) + 1, dwBytesRead, 0) using 0 instead of Overlapped setting, but the program crashed.
so i don't know using what to fix this, another thread? or Overlapped? some actual vb6 code is better cause i'm not familiar with this section, thank you!
I'm quite new to Scapy, and I'm trying to craft an RTS packet and send it to an AP, in order to get a CTS response. However, I'm having a really hard time figuring out the proper way to do it (being a beginner in networking and 802.11 packets doesn't help either).
This is the code I have for now:
bytes = struct.pack("<H", 123) # 123 microseconds
timeval = struct.unpack(">H", bytes)[0]
pkt = RadioTap()/Dot11(addr1 = target_addr, addr2 = my_addr, type = 1, subtype = 11, ID = timeval)
I know that type must be equal to 1 since it's a Control packet, and that subtype must be equal to 11 because it's an RTS packet. However, when I send the packet with either sr() or srp() or sr1() I either get no response back (Scapy waits for a response but nothing gets back so it just continues waiting) or I get the exact message I sent.
This question mentions adding a Dot11Elt() layer at the end, however that changes nothing in my case.
This is the type of response I get back:
And if I open the 0th element of the response tuple with Wireshark, I get:
I've hidden the MAC addresses, but they are the sameas those I put in the packet I sent to the AP (target_addr and my_addr). I'm expecting to get back a CTS with my_addr as "destination address".
What am I doing wrong?
I'm making ping requests to all the server on my domain with Qt
I found inspiration here : how to check computer's state using Qt?
and did like this :
int exitCode = QProcess::execute("ping", QStringList() << "-n 1" << "hostname");
if (0 == exitCode) {
// it's alive
} else {
// it's dead
}
Its working (mostly)
But, here is two problem I can't find solution for :
When I launch, some ugly windows console show up for all the ping, how to hide them ?
Some server are known by the DNS but not working anymore : resulting in this message for a ping :
****************> ping oldserverNotWorkingAnymore
sending a 'ping' request for oldserverNotWorkingAnymore.mydomain [172.20.*.*] with 32 bytes of data
response from 172.20.*.* : Impossible to call host
response from 172.20.*.* : Impossible to call host
response from 172.20.*.* : Impossible to call host
response from 172.20.*.* : Impossible to call host
stat : send = 4, received = 4, lost = 0
which result in the program thinking the host exist while it's not
How to differentiate from a really working ping ?
I am fairly new to SNMP and i have created a SNMP Agent in java using the snmp4j library.
In my code, i have added localhost as a trap destination. I therefore receive the notifications on the port 162 :
targetMIB.addTargetAddress(new OctetString("notification"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("127.0.0.1/162").getValue()),
200, 1,
new OctetString("notify"),
new OctetString("v2c"),
StorageType.permanent);
What i am trying to do now is to receive traps from another ip address using a snmp browser such as iReasoning MIB Browser. But there i cannot manage to add an entry to the target mib.
Am i missing something ?
Thank you.
EDIT :
I want to add an entry using the mib browser to the target Address table. With iReasoning Mib browser i don't have the create row button and with ManageEngine's tool i have an add button but it does not seem to do anything.
I am therefore only trying here to change the row i have created with the code :
Here is a screen shot of the mib browser :
When i try to change the ip address i get an error :
I have tried to set the value using an OctetString with :
127.0.0.1:162
127.0.0.1/162
0700000100A2
0x0700000100A2
but nothing works
For further info, i solved my problem using the NET-SNMP tools.
What i did was :
Download net-snmp binaries
Make sure the mibs are located in the default folder (see readme)
Try a snmpwalk :
snmpwalk -v2c -c [READ_COMMUNITY] 127.0.0.1 targetaddrtable
SNMP-TARGET-MIB::snmpTargetAddrTDomain.'test' = OID: SNMPv2-TM::snmpUDPDomain
SNMP-TARGET-MIB::snmpTargetAddrTAddress.'test' = Hex-STRING: 00 00 00 00 00 A1
SNMP-TARGET-MIB::snmpTargetAddrTimeout.'test' = INTEGER: 1500
SNMP-TARGET-MIB::snmpTargetAddrRetryCount.'test' = INTEGER: 3
SNMP-TARGET-MIB::snmpTargetAddrTagList.'test' = STRING: v2c
SNMP-TARGET-MIB::snmpTargetAddrParams.'test' = STRING:
SNMP-TARGET-MIB::snmpTargetAddrStorageType.'test' = INTEGER: nonVolatile(3)
4) Do a set :
snmpset -v2c -c [COMMUNITY_WRITE] 127.0.0.1 snmpTargetAddrTAddress.'test' x 0000000000A1 snmpTargetAddrTDomain.'test' o 1.3.6.1.6.1.1 snmpTargetAddrTagList.'test' s notify snmpTargetAddrParams.'test' s v2c
snmpTargetAddrRowStatus.'test' i 4
SNMP-TARGET-MIB::snmpTargetAddrTAddress.'test' = Hex-STRING: 00 00 00 00 00 A1
SNMP-TARGET-MIB::snmpTargetAddrTDomain.'test' = OID: SNMPv2-TM::snmpUDPDomain
SNMP-TARGET-MIB::snmpTargetAddrTagList.'test' = STRING: notify
SNMP-TARGET-MIB::snmpTargetAddrParams.'test' = STRING: v2c
SNMP-TARGET-MIB::snmpTargetAddrRowStatus.'test' = INTEGER: createAndGo(4)
the snmpTargetAddrTAddress is a test
I'm trying to send something via socket so I made a simple protocol which is :
[Message length (uint32)][Packet id(uint32)][Message]
So, how can I send a message with this protocol ? I tried this :
message = 'hi'
parent_socket.send([message.length, 2].pack('LL') + message, 0)
and it doesn't seems to work. What I get is just the length and the packet id.
How can I figure this out?
(Updated)
The code I'm using to receive the message is :
if child_socket.ready?
header = child_socket.read(8).unpack('LL')
length = header[0]
packet = header[1]
case packet
when 1
stdin.write(child_socket.read(length))
when 2
puts child_socket.read(length)
#send console
else
Console.show "Unknown packet : #{packet}"
end
The output is 10. Seems normal (4 + 4 + 2)
in that case, length is 2 and packet is 2. So it switch to 'when 2' but it output nothing.
The problem is you are only reading the first 8 byes.
header = child_socket.read(8).unpack('LL')
According to the docs for IO#read, if you don't pass a length, it will read to EOF, which should get everything. So just remove that length parameter:
header = child_socket.read.unpack('LL')