diff --git a/assets/linksys-spa5xx-configtemplate.tt b/assets/linksys-spa5xx-configtemplate.tt
index 4952732011..56dc53d736 100644
--- a/assets/linksys-spa5xx-configtemplate.tt
+++ b/assets/linksys-spa5xx-configtemplate.tt
@@ -2,7 +2,7 @@
[% barge_in = 0 -%]
[% config.url %]
Yes
- [% firmware.baseurl %]/$MA/from/$SWVER/next
+ ($SWVER < [% firmware.maxversion %])? [% firmware.baseurl %]/$MA/from/$SWVER/next
[% phone.stationname %]
[% phone.stationname %]
RFC3265_4235
diff --git a/lib/NGCP/Panel/Controller/Device.pm b/lib/NGCP/Panel/Controller/Device.pm
index e11520af3d..da627694e1 100644
--- a/lib/NGCP/Panel/Controller/Device.pm
+++ b/lib/NGCP/Panel/Controller/Device.pm
@@ -908,11 +908,17 @@ sub dev_field_config :Chained('/') :PathPart('device/autoprov/config') :Args() {
},
};
- $vars->{firmware} = {
- baseurl => 'http://' . $c->req->uri->host . ':' .
+ $vars->{firmware}->{baseurl} = 'http://' . $c->req->uri->host . ':' .
($c->config->{web}->{autoprov_plain_port} // '1444') .
- '/device/autoprov/firmware',
- };
+ '/device/autoprov/firmware';
+ my $latest_fw = $c->model('DB')->resultset('autoprov_firmwares')->search({
+ device_id => $model->id,
+ }, {
+ order_by => { -desc => 'version' },
+ })->first;
+ if($latest_fw) {
+ $vars->{firmware}->{maxversion} = $latest_fw->version;
+ }
my @lines = ();
foreach my $linerange($model->autoprov_device_line_ranges->all) {