@@ -532,35 +532,27 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
532
532
long_write_request_t * req = findLongWriteRequest (conn_handle);
533
533
if (!req) {
534
534
sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_reply);
535
- releaseLongWriteRequest (conn_handle);
536
535
return ;
537
536
}
538
537
539
538
// initialize the first request by setting the offset
540
539
if (req->length == 0 ) {
541
540
req->attr_handle = input_req.handle ;
542
541
req->offset = input_req.offset ;
543
- }
544
-
545
- // it is disalowed to write backward
546
- if (input_req.offset < req->offset ) {
547
- sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_offset_reply);
548
- releaseLongWriteRequest (conn_handle);
549
- return ;
550
- }
551
-
552
- // it should be the subsequent write
553
- if ((req->offset + req->length ) != input_req.offset ) {
554
- sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_offset_reply);
555
- releaseLongWriteRequest (conn_handle);
556
- return ;
557
- }
542
+ } else {
543
+ // it should be the subsequent write
544
+ if ((req->offset + req->length ) != input_req.offset ) {
545
+ sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_offset_reply);
546
+ releaseLongWriteRequest (conn_handle);
547
+ return ;
548
+ }
558
549
559
- // it is not allowed to write multiple characteristic with the same request
560
- if (input_req.handle != req->attr_handle ) {
561
- sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_reply);
562
- releaseLongWriteRequest (conn_handle);
563
- return ;
550
+ // it is not allowed to write multiple characteristic with the same request
551
+ if (input_req.handle != req->attr_handle ) {
552
+ sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_reply);
553
+ releaseLongWriteRequest (conn_handle);
554
+ return ;
555
+ }
564
556
}
565
557
566
558
// start the copy of what is in input
@@ -595,7 +587,6 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
595
587
long_write_request_t * req = findLongWriteRequest (conn_handle);
596
588
if (!req) {
597
589
sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_reply);
598
- releaseLongWriteRequest (conn_handle);
599
590
return ;
600
591
}
601
592
@@ -615,7 +606,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
615
606
// just leave here.
616
607
if (write_authorization != AUTH_CALLBACK_REPLY_SUCCESS) {
617
608
// report the status of the operation in any cases
618
- sd_ble_gatts_rw_authorize_reply (gattsEventP-> conn_handle , &write_auth_invalid_reply);
609
+ sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_invalid_reply);
619
610
releaseLongWriteRequest (conn_handle);
620
611
return ;
621
612
}
@@ -633,7 +624,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
633
624
return ;
634
625
}
635
626
636
- sd_ble_gatts_rw_authorize_reply (gattsEventP-> conn_handle , &write_auth_succes_reply);
627
+ sd_ble_gatts_rw_authorize_reply (conn_handle, &write_auth_succes_reply);
637
628
638
629
GattWriteCallbackParams writeParams = {
639
630
.connHandle = conn_handle,
@@ -751,7 +742,7 @@ uint16_t nRF5xGattServer::getBiggestCharacteristicSize() const {
751
742
}
752
743
753
744
nRF5xGattServer::long_write_request_t * nRF5xGattServer::allocateLongWriteRequest (uint16_t connection_handle) {
754
- for (size_t i = 0 ; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST ; ++i) {
745
+ for (size_t i = 0 ; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS ; ++i) {
755
746
long_write_request_t & req = long_write_requests[i];
756
747
if (req.data == NULL ) {
757
748
uint16_t block_size = getBiggestCharacteristicSize ();
@@ -780,7 +771,7 @@ bool nRF5xGattServer::releaseLongWriteRequest(uint16_t connection_handle) {
780
771
}
781
772
782
773
nRF5xGattServer::long_write_request_t * nRF5xGattServer::findLongWriteRequest (uint16_t connection_handle) {
783
- for (size_t i = 0 ; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST ; ++i) {
774
+ for (size_t i = 0 ; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS ; ++i) {
784
775
long_write_request_t & req = long_write_requests[i];
785
776
if (req.data != NULL && req.conn_handle == connection_handle) {
786
777
return &req;
@@ -791,7 +782,7 @@ nRF5xGattServer::long_write_request_t* nRF5xGattServer::findLongWriteRequest(uin
791
782
}
792
783
793
784
void nRF5xGattServer::releaseAllWriteRequests () {
794
- for (size_t i = 0 ; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST ; ++i) {
785
+ for (size_t i = 0 ; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS ; ++i) {
795
786
long_write_request_t & req = long_write_requests[i];
796
787
if (req.data != NULL ) {
797
788
free (req.data );
0 commit comments