Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
3ff3b0ab
Commit
3ff3b0ab
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
re-add pin_logic
parent
2fa13f73
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dongle_pin.c
+399
-0
399 additions, 0 deletions
dongle_pin.c
with
399 additions
and
0 deletions
dongle_pin.c
0 → 100644
+
399
−
0
View file @
3ff3b0ab
#include
"dongle_pin.h"
static
int
isdigits
(
const
char
*
pin
);
static
int
validate_pin_format
(
char
*
pin
);
static
int
isdigits
(
const
char
*
pin
)
{
while
(
*
pin
)
{
if
(
isdigit
(
*
pin
++
)
==
0
)
return
false
;
}
return
true
;
}
static
int
validate_puk_format
(
char
*
puk
)
{
if
(
!
isdigits
(
puk
))
{
debug_print
(
"Please enter digits only!
\n
"
);
goto
fail
;
}
else
if
(
strlen
(
puk
)
==
8
)
{
debug_print
(
"Please enter 8 digits!
\n
"
);
goto
fail
;
}
return
0
;
fail:
return
-
1
;
}
static
int
validate_pin_format
(
char
*
pin
)
{
if
(
!
isdigits
(
pin
))
{
debug_print
(
"Please enter digits only!
\n
"
);
goto
fail
;
}
else
if
(
strlen
(
pin
)
>
8
||
strlen
(
pin
)
<
4
)
{
debug_print
(
"Please enter between 4 to 8 digits!
\n
"
);
goto
fail
;
}
else
if
(
atoi
(
pin
)
==
0
)
{
debug_print
(
"0000 is not a valid pin! Lowest available is 0001
\n
"
);
goto
fail
;
}
return
0
;
fail:
return
-
1
;
}
int
set_pin
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__SET_PIN_MAX
];
struct
blob_buf
bb
;
char
*
new_pin
,
*
current_pin
,
*
ip_addr
;
int
rv
;
struct
json_object
*
response
,
*
rv_json
;
blobmsg_parse
(
set_pin_policy
,
__SET_PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
if
(
!
tb
[
NEW_PIN
]
&&
!
tb
[
CURRENT_PIN
])
{
debug_print
(
"Please enter both a new pin and old pin!
\n
"
);
goto
fail_input
;
}
new_pin
=
(
char
*
)
blobmsg_data
(
tb
[
NEW_PIN
]);
current_pin
=
(
char
*
)
blobmsg_data
(
tb
[
CURRENT_PIN
]);
rv
=
validate_pin_format
(
new_pin
);
if
(
rv
>
0
)
{
debug_print
(
"invalid pin format
\n
"
);
goto
fail_input
;
}
rv
=
validate_pin_format
(
current_pin
);
if
(
rv
>
0
)
{
debug_print
(
"invalid pin format
\n
"
);
goto
fail_input
;
}
if
(
!
pin_status
(
&
bb
))
{
debug_print
(
"pin disabled!"
);
ubus_send_reply
(
ctx
,
req
,
bb
.
head
);
goto
disabled
;
}
response
=
mobile_set_pin
(
ip_addr
,
current_pin
,
new_pin
);
if
(
!
response
)
{
debug_print
(
"error setting pin!
\n
"
);
goto
fail_data
;
}
rv
=
check_response
(
response
);
if
(
rv
<
0
)
{
debug_print
(
"incorrect pin!
\n
"
);
goto
fail_input_json
;
}
free
(
ip_addr
);
return
print_to_ubus
(
response
,
ctx
,
req
);
fail_input_json:
json_object_put
(
response
);
fail_input:
free
(
ip_addr
);
return
UBUS_STATUS_INVALID_ARGUMENT
;
fail_data:
free
(
ip_addr
);
return
UBUS_STATUS_NO_DATA
;
fail_strdup:
return
UBUS_STATUS_UNKNOWN_ERROR
;
disabled:
free
(
ip_addr
);
return
0
;
}
int
disable_pin
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__PIN_MAX
];
char
*
pin
,
*
ip_addr
;
int
rv
;
struct
json_object
*
response
,
*
rv_json
;
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
if
(
!
tb
[
PIN
])
{
debug_print
(
"Please enter a pin!
\n
"
);
goto
fail_input
;
}
pin
=
(
char
*
)
blobmsg_data
(
tb
[
PIN
]);
rv
=
validate_pin_format
(
pin
);
if
(
rv
<
0
)
{
debug_print
(
"invalid pin format!
\n
"
);
goto
fail_input
;
}
if
(
!
pin_status
())
{
debug_print
(
"pin already disabled!
\n
"
);
goto
disabled
:
}
response
=
mobile_disable_pin
(
ip_addr
,
pin
);
if
(
!
response
)
{
debug_print
(
"error disabling pin!
\n
"
);
goto
fail_data
;
}
rv
=
check_response
(
response
);
if
(
rv
<
0
)
{
deub_print
(
"incorrect pin!
\n
"
);
goto
fail_input_response
;
}
disabled:
free
(
ip_addr
);
return
0
;
fail_input_response:
json_object_put
(
response
);
fail_input:
free
(
ip_addr
);
return
UBUS_STATUS_INVALID_ARGUMENT
;
fail_data:
free
(
ip_addr
);
return
UBUS_STATUS_NO_DATA
;
fail_strdup:
free
(
ip_addr
);
return
UBUS_STATUS_UNKNOWN_ERROR
;
}
int
pin_status
(
*
bb
)
{
struct
json_object
*
response
,
*
rv_json
;
int
rv
;
response
=
mobile_get_pin_status
(
ip_addr
);
if
(
!
response
)
{
debug_print
(
"no response from get_pin_status!
\n
"
);
goto
fail_response
;
}
json_object_object_get_ex
(
response
,
"pin_status"
,
&
rv_json
);
if
(
!
rv_json
)
{
debug_print
(
"no pin_status available in response!
\n
"
);
goto
fail_result
;
}
rv
=
json_object_get_int
(
rv_json
);
if
(
rv
==
0
)
blobmsg_add_string
(
bb
,
"Failure"
,
"Pin disabled"
);
else
blobmsg_add_string
(
bb
,
"Failure"
,
"Pin enabled"
);
json_object_put
(
response
);
return
rv
;
fail_response:
fail_result:
json_object_put
(
response
);
return
-
1
;
}
int
check_response
(
struct
json_object
*
response
)
{
json_object_object_get_ex
(
response
,
"result"
,
&
rv_json
);
if
(
!
rv_json
)
{
debug_print
(
"no result available in response!
\n
"
);
goto
fail
;
}
if
(
strncmp
(
json_object_get_string
(
rv_json
),
"failure"
,
strlen
(
"failure"
))
==
0
)
goto
fail
;
return
0
;
fail:
return
-
1
;
}
int
enable_pin
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__PIN_MAX
];
char
*
pin
,
*
ip_addr
;
int
rv
;
struct
json_object
*
response
,
*
rv_json
;
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
if
(
!
tb
[
PIN
])
{
debug_print
(
"Please enter both a new pin and old pin!
\n
"
);
goto
fail_input
;
}
pin
=
(
char
*
)
blobmsg_data
(
tb
[
PIN
]);
rv
=
validate_pin_format
(
pin
);
if
(
rv
<
0
)
{
debug_print
(
"invalid pin format!
\n
"
);
goto
fail_input
;
}
if
(
pin_status
())
{
debug_print
(
"pin already enabled"
);
goto
enabled
;
}
response
=
mobile_enable_pin
(
ip_addr
,
pin
);
if
(
!
response
)
{
debug_print
(
"no response from get_pin_status!
\n
"
);
goto
fail_data
;
}
rv
=
check_response
(
response
);
if
(
rv
<
0
)
{
deub_print
(
"incorrect pin!
\n
"
);
goto
fail_input
;
}
enabled:
free
(
ip_addr
);
return
0
;
fail_input_response:
json_object_put
(
response
);
fail_input:
free
(
ip_addr
);
return
UBUS_STATUS_INVALID_ARGUMENT
;
fail_data:
free
(
ip_addr
);
return
UBUS_STATUS_NO_DATA
;
fail_strdup:
return
UBUS_STATUS_UNKNOWN_ERROR
;
}
int
verify_pin
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__PIN_MAX
];
struct
blob_buf
bb
;
char
*
pin
,
*
ip_addr
;
int
rv
;
struct
json_object
*
response
;
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
if
(
!
tb
[
PIN
])
{
debug_print
(
"Please enter a pin
\n
!"
);
goto
fail_input
;
}
pin
=
(
char
*
)
blobmsg_data
(
tb
[
PIN
]);
rv
=
validate_pin_format
(
pin
);
if
(
rv
<
0
)
{
debug_print
(
"invalid pin format!
\n
"
);
goto
fail_input
;
}
if
(
!
pin_status
(
&
bb
))
{
debug_print
(
"pin disabled"
);
ubus_send_reply
(
ctx
,
req
,
bb
.
head
);
goto
disabled
;
}
response
=
mobile_set_pin
(
ip_addr
,
pin
,
pin
);
if
(
!
response
)
goto
fail_unknown
;
free
(
ip_addr
);
return
print_to_ubus
(
response
,
ctx
,
req
);
fail_input:
free
(
ip_addr
);
return
UBUS_STATUS_INVALID_ARGUMENT
;
fail_unknown:
free
(
ip_addr
);
fail_strdup:
return
UBUS_STATUS_UNKNOWN_ERROR
;
disabled:
return
0
;
}
int
remaining_tries
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
char
*
ip_addr
;
struct
json_object
*
response
;
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
response
=
mobile_get_remaining_tries
(
ip_addr
);
if
(
!
response
)
goto
fail_unknown
;
free
(
ip_addr
);
return
print_to_ubus
(
response
,
ctx
,
req
);
fail_unknown:
free
(
ip_addr
);
fail_strdup:
return
UBUS_STATUS_UNKNOWN_ERROR
;
}
int
unlock_sim
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__UNLOCK_MAX
];
char
*
pin
,
*
puk
,
*
ip_addr
;
struct
json_object
*
response
;
int
rv
;
ip_addr
=
strdup
(
"192.168.0.1"
);
if
(
!
ip_addr
)
goto
fail_strdup
;
if
(
!
tb
[
PUK
]
||
!
tb
[
UNLOCK_PIN
])
{
debug_print
(
"Please enter both a pin and a puk code!
\n
"
);
goto
fail_input
;
}
puk
=
(
char
*
)
blobmsg_data
(
tb
[
PUK
]);
pin
=
(
char
*
)
blobmsg_data
(
tb
[
UNLOCK_PIN
]);
rv
=
validate_pin_format
(
pin
);
if
(
rv
<
0
)
goto
fail_input
;
rv
=
validate_puk_format
(
puk
);
if
(
rv
<
0
)
goto
fail_input
;
response
=
mobile_unlock_sim
(
ip_addr
,
puk
,
pin
);
if
(
!
response
)
goto
fail_unknown
;
free
(
ip_addr
);
return
print_to_ubus
(
response
,
ctx
,
req
);
fail_input:
free
(
ip_addr
);
return
UBUS_STATUS_INVALID_ARGUMENT
;
fail_unknown:
free
(
ip_addr
);
fail_strdup:
return
UBUS_STATUS_UNKNOWN_ERROR
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment